第一種方法:這個(gè)是刪除單字段圖片的代碼。比較簡單,因?yàn)閳D片字段已經(jīng)預(yù)先存在數(shù)據(jù)庫表的bookpic的字段里面了。
復(fù)制代碼 代碼如下:
!--#include file="conn.asp"-->
%
fileid=trim(request("fileid"))'要?jiǎng)h除的記錄ID
set rs=server.createobject("adodb.recordset")
sql="select * from shop_books where bookid=3090"
rs.open sql,conn,3,2
upfile=rs("bookpic") '帶路徑和文件名
set fso=server.CreateObject("scripting.filesystemobject")
fso.deletefile(server.MapPath(upfile))
set fso=nothing
rs.delete
rs.update
rs.close
set rs=nothing
%>
第二種方法:對于多圖片的
asp程序下大家在添加信息的時(shí)候可以用ewebeditor,這個(gè)可以將文章種的圖片提取后放到一個(gè)字段里面。
復(fù)制代碼 代碼如下:
Id=Request("Id")
If Id="" Then
Response.Write("script>alert('刪除操作失敗:請選擇需要?jiǎng)h除的信息!');hitory.go(-1);/script>")
Else
Id=Split(Id,",")
For i=0 to UBound(Id)
set oRs=SerVer.CreateObject("Adodb.recordset")
sSql = "SELECT D_SavePathFileName FROM "data" WHERE ID="id(i)""
oRs.Open sSql, Conn, 0, 1
If Not oRs.Eof Then
asSavePathFileName = oRs("D_SavePathFileName")
Else
asSavePathFileName=""
End If
oRs.Close
Set oRs=Nothing
Dim aSavePathFileName
if len(aSavePathFileName)>0 then
aSavePathFileName = Split(asSavePathFileName, "|")
Dim n
For n = 0 To UBound(aSavePathFileName)
' 按路徑文件名刪除文件
Call DoDelFile(aSavePathFileName(n))
Next
'刪除文章 www.jb51.net
Conn.Execute("delete from Article where id="id(i)"")
Next
end if
Sub DoDelFile(sPathFile)
'On Error Resume Next
Dim oFSO
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
if objFSO.fileExists(Server.MapPath(sPathFile)) then
oFSO.DeleteFile(Server.MapPath(sPathFile))
end if
Set oFSO = Nothing
End Sub