遇到了删除图片的问题

xyy7309 2009-09-16 12:39:28
一张数据库表有2个字段内有编辑器上传的图片,现在实现的代码只能删除一个字段("nr")内的图片...而("pic")字段内的图片如何同时删除?

请高手指导!

代码如下:
<%
Function RegExp_Execute(patrn,strng)
Dim regEx,Match,Matches,values'建立变量
Set regEx=New RegExp'建立正则表达式
regEx.Pattern=patrn'设置模式
regEx.IgnoreCase=true'设置是否区分字符大小写
regEx.Global=True'设置全局可用性
Set Matches=regEx.Execute(strng)'执行搜索
For Each Match in Matches'遍历匹配集合
values=values&Match.Value&","
Next
RegExp_Execute=values
End Function
%>
<%
dim src
content=(Recordset1.Fields.Item("nr").Value)
regstr="src\=.+?\.(gif|jpg)"
url=Replace(Replace(Replace(RegExp_Execute(regstr,content),"'",""),"""",""),"src=","")
src=split(url,",")
if url<>""then
for i=0 to ubound(src)-1
'删除文件
set fso=Server.CreateObject("scripting.filesystemobject")
fileName=src(i)
myFile=Server.MapPath(fileName)
if fso.FileExists(myFile)then
fso.DeleteFile myFile
end if
set fso=Nothing
%>
<%next
else
%>
<%end if%>

<%
Dim Command2__varName
Command2__varName = "defaultValue"
If (runtimeValue <> "") Then
Command2__varName = runtimeValue
End If
%>
<%

Set Command2 = Server.CreateObject ("ADODB.Command")
Command2.ActiveConnection = MM_Abocnon_STRING
Command2.CommandText = "DELETE FROM Abo_ShangPinZLK WHERE spid =?"
Command2.Parameters.Append Command2.CreateParameter("id", 3, 1, -1, MM_IIF(Request("wzid"), Request("wzid"), Command2__id & ""))
Command2.CommandType = 1
Command2.CommandTimeout = 0
Command2.Prepared = true
Command2.Execute()
%>
...全文
144 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyy7309 2009-09-17
  • 打赏
  • 举报
回复
请大家指导!!!!
liuwei_IT_love 2009-09-16
  • 打赏
  • 举报
回复
<%
dim src,id
id=request.querystring("id")
content=(Recordset1.Fields.Item("nr").Value)
regstr="src\=.+?\.(gif|jpg)"
url=Replace(Replace(Replace(RegExp_Execute(regstr,content),"'",""),"""",""),"src=","")
src=split(url,",")
if url <>""then
for i=0 to ubound(src)-1
'删除文件
set fso=Server.CreateObject("scripting.filesystemobject")
fileName=src(i)
myFile=Server.MapPath(fileName)
if fso.FileExists(myFile)then
fso.DeleteFile myFile
end if
set fso=Nothing
%>
<%next
else
%>
<%end if%>

<%
Dim Command2__varName
Command2__varName = "defaultValue"
If (runtimeValue <> "") Then
Command2__varName = runtimeValue
End If
%>
<%

Set Command2 = Server.CreateObject ("ADODB.Command")
Command2.ActiveConnection = MM_Abocnon_STRING
Command2.CommandText = "DELETE FROM Abo_ShangPinZLK WHERE spid =" &id
Command2.Parameters.Append Command2.CreateParameter("id", 3, 1, -1, MM_IIF(Request("wzid"), Request("wzid"), Command2__id & ""))
Command2.CommandType = 1
Command2.CommandTimeout = 0
Command2.Prepared = true
Command2.Execute()
%>
试一下,因为一般删除语句是根据ID号来查找要删除的字段的

xyy7309 2009-09-16
  • 打赏
  • 举报
回复
请大家指教!
xyy7309 2009-09-16
  • 打赏
  • 举报
回复
请大家指教!
xyy7309 2009-09-16
  • 打赏
  • 举报
回复
请大家指教!
xyy7309 2009-09-16
  • 打赏
  • 举报
回复
请大家指导!!!!
xyy7309 2009-09-16
  • 打赏
  • 举报
回复
现在是记录和"nr"字段内的图片是可以删除了,而"pic"字段中也有图片.不知道如何才能删除"pic"字段中的图片.

例数据库表字段:

id bt nr pic

"nr"字段内容和图片是用编辑1添加的,"pic"字段内容和图片是用编辑2添加的,
现在要实现的是删除记录的同时删除"nr"字段内的图片和"pic"字段内的图片...

而我上面的代码只能删除记录和"nr"字段内的图片...

请大家指导!!!!
不耐烦 2009-09-16
  • 打赏
  • 举报
回复
路径都有了 还删除不了图片了

批量删除不是更方便

你可以 读出 文件夹里的所有图片name
然后循环 跟数据库里的字段做匹配(like或者instr) 如果不存在就删除这个图片

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧