ASP delete data and delete pictures at the same time code _ application Tips

Source: Internet
Author: User
First method: This is the code that deletes the picture of the word segment. Simple, because the picture field already exists in the Bookpic field of the database table.
Copy 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 filename
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 images
Under the ASP program, you can use ewebeditor when adding information, this can be extracted from the article and put into a field.
Copy Code code as follows:

Id=request ("Id")
If id= "" Then
Response.Write (' <script>alert (' delete operation 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 file by path filename
Call Dodelfile (Asavepathfilename (n))
Next
' Delete 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.