想用ASP做动态删除文件,我的代码只能删除数据库中的记录。怎么改才能做到删除文件和数据呢?

[复制链接]
查看11 | 回复1 | 2011-4-4 09:01:56 | 显示全部楼层 |阅读模式
%@LANGUAGE=\"VBSCRIPT\" CODEPAGE=\"936\"%
!--#include file=\"conn.asp\" --
%
Set rs=Server.CreateObject(\"ADODB.Recordset\")
sqlstr=\"select * from upload where tname=\'\"\"\" then
\'set fso=CreateObject(\"scripting.filesystemobject\")
\'fso.deleteFile(request(\"FileName\"))
\'end if
%
script language=\"javascript\"
alert(\"文件删除成功!\");
window.location.href=\'index.asp\';
/script
!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"<a href=\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\" target=\"_blank\">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>\"
html xmlns=\"<a href=\"http://www.w3.org/1999/xhtml\" target=\"_blank\">http://www.w3.org/1999/xhtml</a>\"
head
meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" /
title无标题文档/title
/head
body
/body
/html
表名upload,属性:ID:自动编号,tname:从文件中读取的文件名,文件路径upload\\images\\goods
如果调试成功可以加到100分。
回复

使用道具 举报

千问 | 2011-4-4 09:01:56 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">path=Server.MapPath(\"request(\"FileName\")\")
Set fso = server.CreateObject(\"Scripting.FileSystemObject\")
IF (fso.FileExists(path)) Then
Set delfile = fso.GetFile(path)
delfile.Delete
set delfile=nothing
response.write(\"删除成功!br/\") \'删除成功成功提示!
else
response.write(\"出错了!不存在的文件\")\'出错提示,当服务器不存在该文件时
end if
set fso=nothing

这段是删除服务器文件的核心代码,你可以参考一下~希望对你有用
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行