asp删除图片不能删除提示错误

来源:百度知道 编辑:UC知道 时间:2024/05/01 16:51:41
下面这段代码我是用来删除图片的,但是当记录里有图片的时候提示删除是正确的,但是如果记录里图片为空的时候删除的时候会提示
Server.MapPath() 错误 'ASP 0171 : 80004005'

丢失路径

/admin/all.asp,行 18

必须为 MapPath 方法指定路径参数。以下是这段代码:

<%
Dim action,tuid
action = trim(request.form("action"))
if action = "" then action = trim(request.querystring("action"))
select case action
case "del"
DelID = request("DelID")
Dim DelRs
set fso = Server.CreateObject("scripting.filesystemobject")
set DelRs = server.createobject("adodb.recordset")
' if instr(DelID,",")>0 then ' 删除多个记录
DelID = replace(DelID," ","")
sqlstr = "select tu from pic where id in ("&DelID&")"
DelRs.open sqlstr,conn,1,3
while not DelRs.eof
fileName = DelRs("tu")
myFile=Server.MapPath

if fileName<>"" and not isnull(fileName) then

fileName = DelRs("tu")
myFile=Server.MapPath(fileName)
if fso.FileExists(myFile) then
fso.DeleteFile myFile

end if

在Server.MapPath之前做个判断就行了,
if fileName<>"" then
myFile=Server.MapPath(fileName)
if fso.FileExists(myFile) then
fso.DeleteFile myFile
end if
end if

myFile=Server.MapPath(fileName)
看看你filename里面是什么?估计是空的,或者路径有问题。


fileName = DelRs("tu")
myFile=Server.MapPath(fileName)
if fso.FileExists(myFile) then
fso.DeleteFile myFile
end if
替换为:
fileName = DelRs("tu")
if trim(filename)="" then
myFile=Server.MapPath(fileName)
if fso.FileExists(myFile) then
fso.DeleteFile myFile
end if