主题:  如何配合PureASPUpload插件删除上传文件的教程!

xpilot

职务:普通成员
等级:1
金币:1.0
发贴:192
注册:2001/5/24 14:29:02
#12001/11/13 16:05:48
翻译了一下UDZone.com上一篇介绍如何配合PureASPUpload插件删除上传文件的教程!如果疏漏,敬请指正。
原文地址:
www.udzone.com/ShowDetail.asp?NewsId=1938
www.udzone.com/ShowDetail.asp?NewsId=594
例子下载:
www.udzone.com/Downloads/Tutorial_deletefilewithdemo.zip/deletefile.zip

译文如下:
This tutorial will explain how to delete a file while using an update form or a delete form in conjunction with PureASPUpload 1 & 2.
这个教程将教你在配合使用PureASPUpload 1&2版本的更新或删除表单时,如何删除一个文件。本教程其实是Paul Keur (June 18, 2001) 关于PureASPUpload文件删除教程的一个补充说明!

It's actually very simple.
一般来说非常简单。

First of all you will need to these two functions to make it work.
为了下一步工作,我们首先需要建立两个函数,如下:

'(建一个FileSystemObject对象函数)
<%
Function newFileSystemObject()
set newFileSystemObject=Server.CreateObject("Scripting.FileSystemObject")
End Function
%>

'(判断文件是否存在函数)
<%
Function fileExists(aFileSpec)
fileExists=newFileSystemObject.FileExists(aFileSpec)
End Function
%>

Find your code for either the delete or update sql statement that starts with:
然后从你的网页代码中找到 delete 或 update 的语句片断的位置:

Delete statement:
使用Find菜单搜索如下语句可以找到Delete语句片断位置:

<%
' *** Delete Record: construct a sql delete statement and execute it

Update Statement:
使用Find菜单搜索如下语句可以找到Update语句片断位置:

<%
' *** Update Record: construct a sql delete statement and execute it

Just above these sql statements place the two functions as mentioned above.
在你所搜索到的上面那些SQL语句的地方,把这两个函数的代码加到它们上面去,例如:

----------------------------------------------------------------------------------
<%
Function newFileSystemObject()
set newFileSystemObject=Server.CreateObject("Scripting.FileSystemObject")
End Function
%>
<%
Function fileExists(aFileSpec)
fileExists=newFileSystemObject.FileExists(aFileSpec)
End Function
%>
<%
' *** Delete Record: construct a sql delete statement and execute it
----------------------------------------------------------------------------------


Then insert the code as shown below in the update or delete statement:
然后把下面代码中有颜色的部分插入到updata 或 delete片断的代码中

' execute the delete/update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection

' This is where we delete the file before we delete the record!
' 在我们删除该文件记录在数据库中的信息之前先删除文件!
Set File = CreateObject("Scripting.FileSystemObject")
ImagePath = Server.MapPath("..\upload")
ImagePath = ImagePath & "\" & (rsNews.Fields.Item("image").value)
' check if file exists and if true delete the file
' 判断文件是否已经存在,如为真则删除文件
If fileExists(ImagePath) Then
File.DeleteFile(ImagePath)
End If

MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

As you see it also will work for an update ! This is very handy when using it for example a news administration with images, where it is allowed to edit/change images. This way all images will be deleted from your system/server.
如你所见,这种方法也可以用到update行为里!当你用它来制作一个带有图片的新闻管理
系统时,使用它会给你减少很多麻烦。这中方法可以删除你的系统/服务器上的所有文件。


One important note is that the database field that is called from the recordset, in this example (rsNews.Fields.Item("image").value), needs to be opened before you call this database field. So, if your recordset is below the sql statement for update or delete, move it to the very top.
有一点需要注意的是,数据库的字段是从recordset调用的,例如在本例中
(rsNews.Fields.Item("image").value), 因此在你调用这个数据库字段之前recordset必须已经建立并且被打开。所以,
如果你的recordset语句片断是在update或delete的SQL语句之后话,必须把它移到尽量靠前。
(简单的理解就是,尽量把recordset语句放在文件的最开头部分)

Example code of the recordset:
例如下面的recordset的代码:

<%
Dim rsNews__MMColParam
rsNews__MMColParam = "1"
if (Request.QueryString("ID") <> "") then rsNews__MMColParam = Request.QueryString("ID")
%>
<%
set rsNews = Server.CreateObject("ADODB.Recordset")
rsNews.ActiveConnection = MM_connUDZONE_STRING
rsNews.Source = "SELECT * FROM tblNews WHERE ID = " + Replace(rsNews__MMColParam, "'", "''") + ""
rsNews.CursorType = 0
rsNews.CursorLocation = 2
rsNews.LockType = 3
rsNews.Open()
rsNews_numRows = 0
%>

That's it !
就是这样!

编辑历史:[这消息被xpilot编辑过(编辑时间2001-11-13 16:15:08)]


blshfw

职务:普通成员
等级:1
金币:1.0
发贴:241
注册:2001/5/15 16:44:13
#22001/11/14 9:46:06
非常精彩!收益非浅。
我早上看了之后,下午稍作修改把她应用到同时删除多条记录管理,非常好用!

编辑历史:[这消息被blshfw编辑过(编辑时间2001-11-14 15:21:45)]


5D荣誉斑竹

职务:普通成员
等级:2
金币:10.0
发贴:710
注册:2001/10/24 18:34:42
#32002/3/1 18:06:40
请问xpilot,如何用这个插件在上传时更改文件的名字,比如用上传日期做文件名,可以防止有中文或者是字符的文件名上传到服务器,我一直使用你修正的这个中文版本,它里面可以防止文件重名,好象是在文件名后加上“_1”,既然这个可以实现,不知道能不能也把文件名改了。

这个插件的源码我看不太懂,xpilot!你帮忙看看好不!感谢!



jesron

职务:普通成员
等级:2
金币:1.0
发贴:393
注册:2001/1/27 0:06:31
#42002/3/31 3:25:59
一定要手写的呀?那好累哦,哈哈~~~~
我就是太懒了才选择UD写ASP的。呵呵。看来还是不能全靠软件跟插件,有时也是要动一下手,要不然几块骨头都生诱了。



aSir

职务:普通成员
等级:1
金币:0.0
发贴:78
注册:2002/4/8 23:07:54
#52002/4/8 23:12:27
这是否意味着,只要我上传这个文件,就可以删除服务器上的已知任何文件?



xpilot

职务:普通成员
等级:1
金币:1.0
发贴:192
注册:2001/5/24 14:29:02
#62002/4/9 20:52:08
aSir在上个帖子中说
引用:
这是否意味着,只要我上传这个文件,就可以删除服务器上的已知任何文件?

已做了同时删除上传文件和数据库对应纪录的插件,下载可以到面包论坛!
www.panshiyi.com/mb/forum/mb_forum/click.asp?f2_id=23&f3_id=1659&f3_name=xpilot



lasson

职务:普通成员
等级:1
金币:0.0
发贴:15
注册:2002/10/25 17:02:18
#72002/10/29 11:04:31
我先insert record,后pure asp file upload,但是保存文件时,提示错误:“要进行更改,则需要改变由模板或转换器锁定的代码。此更改将被丢弃。”不知是何原因?