关于上传到服务器目录的文件删除问题(要求删除数据库中的信息与服务器上的文件)。有代码。急用!再线等

guhongzyl 2005-04-19 09:53:20
我是用dreamweaver+asp+access做的网站。

网页放在TeaInfManage文件夹下,上传文件在\TeaInfManage\UploadFiles\中。
上传文件的信息存贮在teachinf.mdb的uploadData表中,其中U_filename存贮文件路径,U_id是主键,U_txt是文件说明,U_name是上传人的名字,U_date是上传日期,当然还有其他字段。
如:U_id U_txt U_filename U_name U_date
3 代理 /teainfmanage/Uploadfiles/xxgch/Calendar/dog.gif zyl 2004-11-22

删除的网页是这样的:
1. adminupload_list.asp (是上传文件的列表)
具体是这样的(connUpload是在dreamweaver中建立的记录集):
文件说明 上传日期 上传路径 上传编辑
connUpload.U_txt connUpload.U_date connUpload.U_filename [删除]
其中在 删除 中建立一个连接页面(具体是利用dreamweaver中的“转到详细页面”服务器行为)adminupdel_list.asp

2. adminupdel_list.asp
这个页面就是一个表格,将上传信息详细的列出来(这个页面其实有没有无所谓)
表格后加一个 表单中的按钮,按钮旁加一个 隐藏区域 用来传递U_id参数,
表单的action是adminupdel.asp,隐藏区域的设置是:name是U_id,value是<%=Request("U_id")%>

3.adminupdel.asp
我的代码是: (这些代码是利用dreamweaver制作的:建立一个命令,用于删除数据库中的信息)
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<!--#include file="Connections/connTeainf.asp" -->

<%
if(Request("U_id") <> "") then Command1__del_id = Request("U_id")
%>


<%

set Command1 = Server.CreateObject("ADODB.Command")
Command1.ActiveConnection = MM_connTeainf_STRING
Command1.CommandText = "DELETE FROM uploadData WHERE U_id =" + Replace(Command1__del_id, "'", "''") + ""
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%>



'下面这句是用dreamweaver中的刷新,跳转到adminupload_list.asp页面
<meta http-equiv="refresh" content="1;URL=adminupload_list.asp">





我的问题是: 那位大侠可以将删除服务器上的文件的那部分代码补上啊??????
偶急用,在线等。
...全文
300 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
chi0591 2005-05-17
  • 打赏
  • 举报
回复
删除数据库记录好,调用call DeleteFile(s_FileName)
就ok了
chi0591 2005-05-17
  • 打赏
  • 举报
回复
其中s_FileName是带相对路径的例如:article/uploadfile/aa.gif格式
Sub DeleteFile(s_FileName)
On Error Resume Next
Dim fso, s_MapFileName
Set fso = Server.CreateObject("Scripting.FileSystemObject")
s_MapFileName = Server.MapPath(s_FileName)
If fso.FileExists(s_MapFileName) Then
fso.DeleteFile(s_MapFileName)
End If
Set fso = Nothing
End Sub
guhongzyl 2005-05-12
  • 打赏
  • 举报
回复
我现在可以上传啊,但是上传以后无法删除啊。
我是想解决删除的问题。
chang1216 2005-04-27
  • 打赏
  • 举报
回复
<%'on error resume next
Set obj = Server.CreateObject("LyfUpload.UploadFile")
if obj.request("bbs_user_name")<>"" then

obj.extname="gif,jpg,bmp,doc,rar,zip,ppt,txt" '设置可以接受扩展名

bbs_user_name = obj.request("bbs_user_name") '得到form元素的值
bbs_user_ip = request.ServerVariables("REMOTE_ADDR")
bbs_title=obj.request("bbs_title")
bbs_context=obj.request("bbs_context")
bbs_img=obj.request("radiobutton")
bbs_firstid=obj.request("bbs_firstid")
upload_dir=server.MapPath("upload") '要上传文件存放的文件夹的绝对路径
path=""
response.write bbs_firstid
'response.end

for i=1 to request.QueryString("time")
filename=now
filename = Replace(filename, ":", "")
filename = Replace(filename, "-", "")
filename = Replace(filename, " ", "") & i'得到一个字符串时间,比如20030809103445
fileinput="File" & i '第n个文件上传框

ss=obj.SaveFile(fileinput, upload_dir, true)

if ss="1" or ss="" or ss="0" or isempty(ss)=true then '如果有不符合条件的,就全部删除
call delete_fun(upload_dir,path,obj.extname)
else
kuozhanming=InstrRev(ss,".")
kuozhanming=right(ss,len(ss)-kuozhanming+1) '得到扩展名,例如.doc

filename=filename & kuozhanming '形成一个真正的文件名,例如20031022105733.doc

set fso=CreateObject("Scripting.FileSystemObject")
aa=upload_dir & "\" & ss
bb=upload_dir & "\" & filename
'response.Write(bb)
fso.MoveFile aa,bb'///将上传的文件改名为20031022105733.doc
file_ok=file_ok & "<img src=uploadpic/"&filename&" title="&filename&" height=100 width=100 border=0>" & filename &"</img>"

set fso=nothing
path=path & filename & "@%@" '////记住所有文件的名字,以便入库,并用@%@作为分割符
end if
next
'response.Write(file_ok)
filename=now
filename = Replace(filename, ":", "")
filename = Replace(filename, "-", "")
filename = Replace(filename, " ", "") & i '得到一个字符串时间,比如20030809103445
sql="select * from hrbweb_bbs "

set rslcz=server.CreateObject("adodb.recordset")
set rslcz=rs(sql,conn)
rslcz.addnew
rslcz(1)=bbs_user_name
rslcz(2)=request.ServerVariables("REMOTE_HOST")
rslcz(3)=bbs_img
rslcz(4)=bbs_title
rslcz(5)=bbs_context
rslcz(6)=bbs_answerCount+1
if bbs_firstid<>"" then
rslcz("bbs_firstid")=bbs_firstid
end if
rslcz("bbs_date")=now
rslcz("bbs_fileName")=path

rslcz.update

response.Redirect("default.asp")




else
Response.Write("<center><font size=2>要添加的记录主题不能为空 ,请<a href='javascript:history.go(-1);'>返回</a>。</font></center>")
response.end
end if
'//////////////////////删除文件
function delete_fun(fold,filename,kuozhanming)
tmp=Split(filename,"@%@")
set fso=CreateObject("Scripting.FileSystemObject")
i=ubound(tmp)
if i>0 then
for i=0 to i
'response.Write(tmp(i))
fso.deletefile (fold & "\" & tmp(i))
next
end if
response.Write("<center><font size=2>您上传的文件类型不正确,只能上传" & kuozhanming & ",请<a href='javascript:history.go(-1);'>返回</a>。</font></center>")
response.end
end function
'////////////////////////入库操作

%>
以前写过的 希望对你能有帮助 可以上传多个文件
guhongzyl 2005-04-27
  • 打赏
  • 举报
回复
上楼的兄弟可以给出代码么?
偶不怎么会的?

谢谢了啊!
cumtsiee 2005-04-23
  • 打赏
  • 举报
回复
楼上的兄弟看清主题啊!
不是叫你列文件的吧!

偶看了一下,是不是楼主的那个数据库中存贮文件路径的字段的问题啊。
要不要用字符串操作函数将字段U_filename中的"/teainfmanage"去掉,然后在再用server.mappath,再用fso删除。


satans18 2005-04-23
  • 打赏
  • 举报
回复
以上是列出一个文件夹里面全部的文件,还带分页功能
satans18 2005-04-23
  • 打赏
  • 举报
回复
<%
if request("page")<>"" then
currentPage=cint(request("page"))
else
currentPage=1
end if
MaxPerPage=PageCount

UploadDir = "../images/uploadpic"
strFileName="admin_picmang.asp"

TruePath=Server.MapPath(UploadDir)
If not okjj.IsObjInstalled("Scripting.FileSystemObject") Then
Response.Write "<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
Else
set fso=CreateObject("Scripting.FileSystemObject")
if request("Action")="Del" then
call DelFiles()
end if

if fso.FolderExists(TruePath)then
FileCount=0
TotleSize=0
Set theFolder=fso.GetFolder(TruePath)
For Each theFile In theFolder.Files
FileCount=FileCount+1
TotleSize=TotleSize+theFile.Size
next
totalPut=FileCount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if

end if
if currentPage=1 then
showContent
showpage2 strFileName,totalput,MaxPerPage
response.write "<br><div align='center'>本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotleSize\1024 & "</b> K</div>"
else
if (currentPage-1)*MaxPerPage<totalPut then
showContent
showpage2 strFileName,totalput,MaxPerPage
response.write "<br><div align='center'>本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotleSize\1024 & "</b> K</div>"
else
currentPage=1
showContent
showpage2 strFileName,totalput,MaxPerPage
response.write "<br><div align='center'>本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotleSize\1024 & "</b> K</div>"
end if
end if
else
response.write "找不到文件夹!可能是配置有误!"
end if
end if

sub showContent()
dim c
FileCount=0
TotleSize=0
%>
<form action="" name="form1" method="post">
<table width="95%" border="1" cellspacing="0" cellpadding="3" align="center" bordercolorlight="#ECEEE4" bordercolordark="#CCCABC">

<tr>
<td colspan="7" align="center" height="30" background="image/tablebg.gif"><b>上
传 图 片 管 理</b> </td>
</tr>
<tr align="center" valign="middle">
<td height="25">选中 <br> </td>
<td height="25">文件名</td>
<td height="25">文件大小</td>
<td height="25">文件类型</td>
<td height="25">最后修改时间</td>
<td height="25">操作</td>
</tr>
<%

For Each theFile In theFolder.Files
c=c+1
if FileCount>=MaxPerPage then
exit for
elseif c>MaxPerPage*(CurrentPage-1) then
%>
<tr align="center" valign="middle">
<td height="25"><input name="FileName" type="checkbox" id="FileName" value="<%=theFile.Name%>"></td>
<td height="25"><a href="<%=(UploadDir & "/" & theFile.Name)%>" target="_blank"><strong><%=theFile.Name%></strong></a></td>
<td height="25"><%=theFile.size%>字节</td>
<td height="25"><%=theFile.type%></td>
<td height="25"><%=theFile.DateLastModified%></td>
<td height="25"><a href="admin_picmang.asp?Action=Del&FileName=<%=theFile.Name%>" onclick="{if(confirm('你真的要删除此文件吗!')){this.document.form1.submit();return true;}return false;}">删除</a></td>
</tr>
<%
FileCount=FileCount+1
TotleSize=TotleSize+theFile.Size
end if
Next
%>

</table>
<table width="95%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="200" height="30"><input name="chkall" type="checkbox" id="chkall" onClick="javascript:CheckAll(this.form)" value="checkbox">
选中本页显示的所有文件</td>
<td><input name="Action" type="hidden" id="Action" value="Del">
<input type="submit" name="Submit" value="删除选中的文件"></td>
</tr>
</table>
</form>
<%
end sub
sub showpage2(sfilename,totalnumber,maxperpage)
dim n, i,strTemp
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
strTemp= "<table align='center'><form name='showpages' method='Post' action='" & sfilename & "'><tr><td>"
strTemp=strTemp & "共 <b>" & totalnumber & "</b> 个文件,占用 <b>" & TotleSize\1024 & "</b> K   "
'sfilename=okjj.JoinChar(sfilename)
if CurrentPage<2 then
strTemp=strTemp & "首页 上一页 "
else
strTemp=strTemp & "<a href='" & sfilename & "?page=1'>首页</a> "
strTemp=strTemp & "<a href='" & sfilename & "?page=" & (CurrentPage-1) & "'>上一页</a> "
end if

if n-currentpage<1 then
strTemp=strTemp & "下一页 尾页"
else
strTemp=strTemp & "<a href='" & sfilename & "?page=" & (CurrentPage+1) & "'>下一页</a> "
strTemp=strTemp & "<a href='" & sfilename & "?page=" & n & "'>尾页</a>"
end if
strTemp=strTemp & " 页次:<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
strTemp=strTemp & " <b>" & maxperpage & "</b>" & "个文件/页"
strTemp=strTemp & " 转到:<select name='page' size='1' onchange='javascript:submit()'>"
for i = 1 to n
strTemp=strTemp & "<option value='" & i & "'"
if cint(CurrentPage)=cint(i) then strTemp=strTemp & " selected "
strTemp=strTemp & ">第" & i & "页</option>"
next
strTemp=strTemp & "</select>"
strTemp=strTemp & "</td></tr></form></table>"
response.write strTemp
end sub

sub DelFiles()
dim whichfile,arrFileName,i
whichfile=trim(Request("FileName"))
if whichfile="" then exit sub
if instr(whichfile,",")>0 then
arrFileName=split(whichfile,",")
for i=0 to ubound(arrFileName)
if left(trim(arrFileName(i)),3)<>"../" and left(trim(arrFileName(i)),1)<>"/" then
whichfile=server.MapPath(UploadDir & "/" & trim(arrFileName(i)))
set thisfile=fso.GetFile(whichfile)
thisfile.Delete True
end if
next
else
if left(whichfile,3)<>"../" and left(whichfile,1)<>"/" then
Set thisfile = fso.GetFile(server.MapPath(UploadDir & "/" & whichfile))
thisfile.Delete True
end if
end if
Response.Write("<script>alert(""删除成功"");location.href=""admin_picmang.asp"";</script>")
end sub
%>
guhongzyl 2005-04-23
  • 打赏
  • 举报
回复
大家多帮忙啊!

偶只有80分了,如果谁搞定这个问题,偶都给了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
guhongzyl 2005-04-23
  • 打赏
  • 举报
回复
首先感谢wanghui0380(放歌)帮忙。
但是我用您的代码不能删除文件啊,同时连数据库中的记录也删除不了!
(我原来是用dreamweaver中的命令删除记录的)


wanghui0380 2005-04-21
  • 打赏
  • 举报
回复


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<!--#include file="Connections/connTeainf.asp" -->

<%
'函数
function DeleteFile(Filename) '删除文件
if Filename<>"" then
Set fso = server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(Filename) then
fso.DeleteFile Filename
end if
set fso = nothing
end if
end function
if(Request("U_id") <> "") then Command1__del_id = Request("U_id")
%>


<%
set rs=server.createobject("adodb.recordset")
sql="select * from uploadData where U_id ="&request("U_ID")
rs.open sql,MM_connTeainf_STRING,3,3
filename=server.MapPath(trim(rs("U_filename")))
rs.delete
rs.updata
rs.close
set rs=nothing
'调用函数
DeleteFile filename
%>
netsymbol 2005-04-21
  • 打赏
  • 举报
回复
没试过帮忙顶!!
大圆镜智1222 2005-04-21
  • 打赏
  • 举报
回复
数据库定位到那个记录,假设记录集用rs

delfile=server.mappath( rs("U_filename"))

Set fso = CreateObject("Scripting.FileSystemObject")
Set f2 = fso.getFile(delfile)
f2.Delete
set f2=nothing
set fso=nothing
yuyijw 2005-04-21
  • 打赏
  • 举报
回复
提出文件路径用fso删除文件
The_younger 2005-04-21
  • 打赏
  • 举报
回复
哈哈哈哈哈
就只有人顶,没人答啊???????????
偶也需要这个问题的解决方法啊,也顶~~~~~~~~~~~~
cnhxjtoa 2005-04-21
  • 打赏
  • 举报
回复
up
guhongzyl 2005-04-19
  • 打赏
  • 举报
回复
还是没人啊!
偶在顶
guhongzyl 2005-04-19
  • 打赏
  • 举报
回复
偶自己顶一下!
guhongzyl 2005-04-19
  • 打赏
  • 举报
回复
偶顶顶顶!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧