ASP跟据数据库路径删除文件夹下的图片

来源:百度知道 编辑:UC知道 时间:2024/06/21 19:50:53
大家都知道,上传图片后,删除的只是数据库里的记录,并没有删除服务器上的图片,从而导至堆积很多无用的图片。
我想实现查找数据库图片的路径(有很多条记录),再跟据路径找到文件夹(所有上传的图片都放在此文件夹下),再将数据库中没有此图片名的删除掉!

请问有没有完整的asp代码啊??

非常之感谢!
不知道是我不会用还是怎么的?

我设置defaultpicurl="../images/22.jpg"

uploadfiles="../images/22.jpg|../images/23.jpg|../images/24.jpg"

运行后没有点提示,不知道是怎么回事

我给你的案例中的图片存储占用了两个字段,一个首页图片地址DefaultPicUrl,另一个是所有图片地址UploadFiles所有图片地址集由|连接。
这是在更新这一篇文章的时候删除多余文件。可以用这个算法作一个批处理。
'***************************************
'删除无用的上传文件
if ObjInstalled=True and UploadFiles<>"" then
dim fso,strRubbishFile
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if instr(UploadFiles,"|")>1 then
dim arrUploadFiles,intTemp
arrUploadFiles=split(UploadFiles,"|")
UploadFiles=""
for intTemp=0 to ubound(arrUploadFiles)
if instr(Content,arrUploadFiles(intTemp))<=0 and arrUploadFiles(intTemp)<>DefaultPicUrl then
strRubbishFile=server.MapPath("../" & arrUploadFiles(intTemp))
if fso.FileExists(strRubbishFile) then
fso.DeleteFile(strRubbishFile)
response.write "<br><li>" & arrUploadFiles(intTemp) & "在文章中没有用到,也没有被设为首页图片,所以已经被删除!<