To achieve deletion of records and deletion of pictures at the same time, generally for the sake of performance, the editor is used to save the pictures in the article in a field. Multiple pictures are separated by commas to facilitate later deletion processing. The first method: This is the code to delete single-field images. It's relatively simple, because the picture field is already pre-existing in the bookpic field of the database table.
Copy the code code as follows:
<!--#include file=conn.asp-->
<%
fileid=trim(request(fileid))'ID of the record to be deleted
set rs=server.createobject(adodb.recordset)
sql=select * from shop_books where bookid=3090
rs.open sql,conn,3,2
upfile=rs(bookpic) 'With path and file name
set fso=server.CreateObject(scripting.filesystemobject)
fso.deletefile(server.MapPath(upfile))
set fso=nothing
rs.delete
rs.update
rs.close
set rs=nothing
%>
The second method: for multiple pictures
Under the ASP program, you can use ewebeditor when adding information. This can extract the pictures of the article and put them into a field.
Copy the code code as follows:
Id=Request(Id)
If Id= Then
Response.Write(<script>alert('Delete operation failed: Please select the information to be deleted!'); 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)
'Delete files by path file name
Call DoDelFile(aSavePathFileName(n))
Next
'Delete article www.vevb.com
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