28,391
社区成员
发帖
与我相关
我的任务
分享
<%
dim conter
center="新闻内容...."
'==读取文章内容里的图片地址
Dim objRegExp,Matches,Match,s_str,fso,path
set fso=server.CreateObject("scripting.filesystemobject") '设置fso对像
Set objRegExp = New Regexp '建立正则规则
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "src\=.+?\.(gif|jpg|jpeg|png|bmp)" '提取的是这几种图片格式
Set Matches =objRegExp.Execute(center) '开始搜索
For Each Match in Matches '循环执行
s_str=Lcase(replace(Match.Value,"src=","")) '替换字符并转成小写
s_str=replace(replace(s_str,"""",""),"'","") '替换单双引号
If left(s_str,13)="/fuploadfile/" Then '判断是不是本站图片地址
path=Server.MapPath(s_str) '获取服务器物理路径
If fso.FileExists(path) Then '判断文件是否存在
fso.deleteFile(path) '删除文件
End If
End If
Next
%>
set fso=server.CreateObject("scripting.filesystemobject")
function delfile(folderpath,filename)'folderpath为你的当前页面相对于文件的存储路径
if trim(filename&"")<>"" then'判断文件名是否为空再执行是否删除操作
filepath=server.MapPath(folderpath&"/"&filename)
fso.DeleteFile filepath
end if
end function
delfile("../xxx/xxxx",rs("pic1"))
delfile("../xxx/xxxx",rs("pic2"))
delfile("../xxx/xxxx",rs("pic3"))
delfile("../xxx/xxxx",rs("pic4"))
delfile("../xxx/xxxx",rs("pic5"))
set fso=nothing
dim conter
center=rs("cntnt")'取得新闻内容
'==下面读取文章内容里的图片地址
Dim objRegExp,Matches,Match,s_str,fso,path
set fso=server.CreateObject("scripting.filesystemobject") '设置fso对像
Set objRegExp = New Regexp '建立正则规则
objRegExp.IgnoreCase = True
objRegExp.Global = True
'objRegExp.Pattern = "src\=.+?\.(gif|jpg|jpeg|png|bmp)" '提取的是这几种图片格式
objRegExp.Pattern = "\s+src\s*=\s*['""]?([^\s'"">]+\.(jpg|jpeg|gif|png|bmp))" '提取的是这几种图片格式
Set Matches =objRegExp.Execute(center) '开始搜索
For Each Match in Matches '循环执行
s_str=LCase(Match.submatches(0)) '替换字符并转成小写
' If left(s_str,28)="/images/aloesky_uploadfiles/" Then '判断是不是本站图片地址(小写),这里这么写是有BUG的,因为图片很有可能会带本站的网址,所以要换成
if instr(s_str,,"本站的网址")>0 or left(s_str,28)="/images/aloesky_uploadfiles/" then
path=Server.MapPath(s_str) '获取服务器物理路径
If fso.FileExists(path) Then '判断文件是否存在
fso.deleteFile(path) '删除文件
End If
End If
Next
dim conter
center=rs("cntnt")'取得新闻内容
'==下面读取文章内容里的图片地址
Dim objRegExp,Matches,Match,s_str,fso,path
set fso=server.CreateObject("scripting.filesystemobject") '设置fso对像
Set objRegExp = New Regexp '建立正则规则
objRegExp.IgnoreCase = True
objRegExp.Global = True
'objRegExp.Pattern = "src\=.+?\.(gif|jpg|jpeg|png|bmp)" '提取的是这几种图片格式
objRegExp.Pattern = "\s+src\s*=\s*['""]?([^\s'"">]+\.(jpg|jpeg|gif|png|bmp))" '提取的是这几种图片格式
Set Matches =objRegExp.Execute(center) '开始搜索
For Each Match in Matches '循环执行
s_str=LCase(Match.submatches(0)) '替换字符并转成小写
If left(s_str,28)="/images/aloesky_uploadfiles/" Then '判断是不是本站图片地址(小写)
path=Server.MapPath(s_str) '获取服务器物理路径
If fso.FileExists(path) Then '判断文件是否存在
fso.deleteFile(path) '删除文件
End If
End If
Next
id=trim(request("id"))
if id = "" then
response.write "<SCRIPT language=JavaScript>alert('您没有选择删除项!');"
response.write"this.history.back(-1);></SCRIPT>"
response.end
else
idlist=id '取得上一个页面传过来的待删除id值
if instr(idlist,",")>0 then 'instr函数用于判断上一个页面传过来的id数量,其值大于0,就表示是批量选择
idarr=split(idlist) '构建id数组。
for i = 0 to ubound(idarr) '开始遍历,以id数组的最大个数为循环次数-ubound:数组的最大下标
nid=cint((idarr(i)))
call deleteannounce(nid) '循环删除每个id值的新闻以及图片的函数。
next
else '如果不是批量,只有一个id值,就表示只删除一笔
call deleteannounce(idlist) '直接调用删除函数。
end if
end if
call connclose()
response.write "<SCRIPT language=JavaScript>alert('删除成功 \n \n 点击确定返回列表');"
response.write"this.location.href='news_mgr.asp';</SCRIPT>"
response.end
sub deleteannounce(ID)
sqlDel="select * from News where ID=" & ID
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sqlDel,conn,1,3
dim conter
center=rs("cntnt")'取得新闻内容
'==下面读取文章内容里的图片地址
Dim objRegExp,Matches,Match,s_str,fso,path
set fso=server.CreateObject("scripting.filesystemobject") '设置fso对像
Set objRegExp = New Regexp '建立正则规则
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "src\=.+?\.(gif|jpg|jpeg|png|bmp)" '提取的是这几种图片格式
Set Matches =objRegExp.Execute(center) '开始搜索
For Each Match in Matches '循环执行
s_str=Lcase(replace(Match.Value,"src=","")) '替换字符并转成小写
s_str=replace(replace(s_str,"""",""),"'","") '替换单双引号
If left(s_str,28)="/images/aloesky_UploadFiles/" Then '判断是不是本站图片地址
path=Server.MapPath(s_str) '获取服务器物理路径
If fso.FileExists(path) Then '判断文件是否存在
fso.deleteFile(path) '删除文件
End If
End If
Next
rs.delete
rs.update
call rsclose
end sub
报错,加上On Error Resume Next后,不但图片删除不了,连文字都删除不了http://127.0.0.1/adminP/adminP_ueditor/asp/adminP_upload1/20140327/13958995628520384.jpg
域名字数在变化,最右边最终的文件夹名称也是变化的。
<!--#include file="code.asp"-->
<!--#include file="adovbs.inc"-->
<%
Set conn=server.CreateObject("adodb.connection")
connstr="provider=microsoft.jet.oledb.4.0;Jet OLEDB:Database Password=;data source="&server.mappath("/dbs/# @XXX.mdb")
conn.open connstr
If Err Then
err.Clear
call connclose()
response.write"<SCRIPT language=JavaScript>alert('数据库后台配置被更改,请联络开发者!');"
response.write"javascript:history.go(-1)</SCRIPT>"
response.end
End If
sub connclose()
conn.close
set conn=nothing
end sub
sub rsclose()
rs.close
set rs=nothing
end sub
sub rs1close()
rs1.close
set rs1=nothing
end sub
sub rs2close()
rs2.close
set rs2=nothing
end sub
sub rs3close()
rs3.close
set rs3=nothing
end sub
sub rs4close()
rs4.close
set rs4=nothing
end sub
sub rs5close()
rs5.close
set rs5=nothing
end sub
sub rs6close()
rs6.close
set rs6=nothing
end sub
sub rs7close()
rs7.close
set rs7=nothing
end sub
sub rs8close()
rs8.close
set rs8=nothing
end sub
sub rs9close()
rs9.close
set rs9=nothing
end sub
sub rs10close()
rs10.close
set rs10=nothing
end sub
sub rsXclose()
rsX.close
set rsX=nothing
end sub
%>
<img src="http://127.0.0.1/user/user_ueditor/asp/upload1/20140326/13958410089191923.jpg" style="float:none;" title="2.jpg"/>
那么取数据的删除语句:
sql="select D_SavePathFileName from news where news_id="&did
应该怎么取?直接:select cntnt from...吗?
再则,我测试了一下,用了SUB后,数据库conn.asp内的sub开始报错了
<%
'前面数据库连接语句...
dim id,idlist,idarr,nid
if isempty(trim(request("chkid"))) then '这里的chkid相当于你的文章或者产品id.
response.write "<SCRIPT language=JavaScript>alert('非法请求,您未选择删除项!');"
response.write"this.history.back(-1);></SCRIPT>"
response.end
else
idlist=trim(request("chkid")) '取得上一个页面传过来的待删除id值
if instr(idlist,",")>0 then 'instr函数用于判断上一个页面传过来的id数量,其值大于0,就表示是批量选择
idarr=split(idlist) '构建id数组。
for i = 0 to ubound(idarr) '开始遍历,以id数组的最大个数为循环次数
nid=cint((idarr(i)))
call deleteannounce(nid) '循环删除每个id值的新闻以及图片的函数。
next
else '如果不是批量,只有一个id值,就表示只删除一笔
call deleteannounce(idlist) '直接调用删除函数。
end if
end if
conn.close
set conn=nothing
response.write "<SCRIPT language=JavaScript>alert('删除成功!');"
response.write"this.location.href='news_list.asp';</SCRIPT>"
response.end
sub deleteannounce(did) '用于删除数据(包括数据库记录和附件)的函数定义
dim rs,sql,picstr
set rs=server.createobject("adodb.recordset")
sql="select D_SavePathFileName from news where news_id="&did
rs.open sql,conn,1,1
picstr=rs("D_SavePathFileName")
rs.close
set rs=nothing
if picstr<>"" then
picstr=replace(picstr,"/","\")
Set FObject=Server.CreateObject("Scripting.FileSystemObject")'建立对象
if instr(picstr,"|")>0 then '如果是多张图片,就循环删除
dim picArr
picArr=split(picstr,"|")
for i=0 to ubound(picArr)
if Fobject.FileExists(Server.MapPath(picArr(i))) then '判断文件是否存在
Fobject.deleteFile server.mapPath(picArr(i))
end if
next
else '如果是单张图片,就直接判断删除。
if Fobject.FileExists(Server.MapPath(picstr)) then '判断文件是否存在
Fobject.deleteFile server.mapPath(picstr)
end if
end if
set FObject=nothing
end if
sql="delete from news where news_id="&(did) '删除新闻的数据。
conn.execute sql
sql1="delete from newspl where ssnews="& did '删除相关的评论。
conn.execute sql1
if err.Number<>0 then
err.clear
response.write "删 除 失 败 !<br>"
end if
End sub
conn.close
set conn=nothing
%>
'单条删除
<a href="act.asp?method=del&id=<%=rs("id")%>" target=_self> 点此删除</a>
当然,也要考虑多条删除的问题,就是在文章(产品)列表前,给个复选框来实现批量删除记录。