ASP code for deleting data and images at the same time

Source: Internet
Author: User

Method 1: Delete the image with a single FieldCode. It is relatively simple because the image field already exists in the bookpic field of the database table. Copy code The Code is 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
%>

Method 2: For multi-Image
ASP Program You can use ewebeditor when adding information. Article The image is extracted and put into a field. Copy code The Code is as follows: Id = request ("ID ")
If Id = "" then
Response. Write ("<SCRIPT> alert ('deletion failed: Please select the information you want to delete! '); 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 objects by path file name
Call dodelfile (asavepathfilename (n ))
Next
'Delete an article 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.