asp 删除数据并一同删除图片的代码
发布时间:2023-06-10 13:14:29 所属栏目:Asp教程 来源:
导读:实现删除记录同时删除图片,一般的情况为了性能都是用编辑器的同时将文章中的图片,保存在一个字段里面,多个图片用逗号分开,方便后期的删除处理。
第一种方法:这个是删除单字段图片的代码。比较简单,因为图片
第一种方法:这个是删除单字段图片的代码。比较简单,因为图片
实现删除记录同时删除图片,一般的情况为了性能都是用编辑器的同时将文章中的图片,保存在一个字段里面,多个图片用逗号分开,方便后期的删除处理。 第一种方法:这个是删除单字段图片的代码。比较简单,因为图片字段已经预先存在数据库表的bookpic的字段里面了。 复制代码代码如下: <!--#include file="conn.asp"--> <% fileid=trim(request("fileid"))'要删除的记录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程序下大家在添加信息的时候可以用ewebeditor,这个可以将文章种的图片提取后放到一个字段里面。 复制代码代码如下: Id=Request("Id") If Id="" Then Response.Write("<script>alert('删除操作失败:请选择需要删除的信息!');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.cuoxin.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 (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐