上传组件 ASPUpload 使用说明

时间:2008-09-11 14:38:00 

当然首先得去下载ASPupload 程序,安装后使用!

官方网站下载:http://www.aspupload.com/

使用ASP实现文件上载到WEB服务器

ASPupload 2.0版,相关源文件如下(uploadTest.htm):

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上载客户端</title>
</head>
<body>
<form method="POST" action="uploadTest1.asp" enctype="multipart/form-data"
name="UPloadForm">
<p><input type="file" Name="File1"> </p>
<p><input type="submit" value="Submit" name="Upload"></p>
</form>
</body>
</html>

其中客户端文件要注意两点:
* 文件上载提交表单(Form)的enctype必须指定为“multipart/form-data”
* 语句<input type="file" Name="File1">表示上载文件域,用户可以在该域中输入或选定文件。

服务器端源文件如下(uploadTest1.asp):

<%response.buffer=true%>
<html>
<%Set Upload=Server.createobject("Persits.Upload.1") '创建文件上载组件
Count=Upload.Save("e:/aspupload") '将客户端文件保存到WEB服务器端的本地硬盘上%> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Upload Test</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
</head>
<body>
<p>上载了<%=Count%>个文件</p>
<p>File has been uploaded.</p>
</body>
</html>

其中,脚本Set Upload=Server.createobject("Persits.Upload.1")创建了文件上载组件,该组件通过调用Save方法将浏览器端的文件内容保存到指定路径。

将文件存在数据库中

将文件保存在数据库中主要用了ASPUpLoad组件中文件对象的ToDatabase方法。源文件如下:

客户端源文件(uploadToDB.htm):

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上载客户端</title>
</head>
<body>
<form method="POST" action="UploadToDB.asp" enctype="multipart/form-data"
name="FormUpload">
<p><input type="file" name="FileUpload"> </p>
<p><input type="submit" value="上载" name="B1"></p>
</form>
<p><a href="readFile.asp">读取数据库中文件</a></p>
</body>
</html>

服务器端源文件(uploadToDB.asp):

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上载到数据库</title>
</head>
<body>
<%Set Upload=Server.createobject("Persits.Upload.1")
Count=Upload.Save("e:/aspupload")
on error resume next
set FileObj=Upload.Files("FileUpload")
SQL="insert into upLoadFile (Title,FileName,Content) values ('"&FileObj.Path&"','"&FileObj.Path&"',?)"
response.write SQL
FileObj.ToDatabase "DSN=FileUpload;UID=sa;",SQL
if Err<>0 then
Response.write "Error Saving the file:"&Err.Description
else
FileObj.delete
response.write "Success!"
end if
%>
</body>
</html>

从数据库中读取文件内容并发送给客户端浏览器

从数据库中读取内容在发送给浏览器之前,首先必须让浏览器知道内容的数据类型,这通过向客户端发送ContentType描述实现。为简单起见,这里假设发送的内容是Word文档,并且显示最新插入的记录。源文件如下:

客户端源文件为uploadToDB.htm(同上一部分的客户端文件)。

服务器端源文件(readFile.asp):

<%Response.Expires = 0
response.buffer=true%>
<%response.clear
Response.ContentType = "application/msword"
set conn=server.createobject("adodb.connection")
conn.open "DSN=FileUpload;UID=sa;"
set rs1=conn.execute("select maxid=max(id) from uploadFile")
SQL="select * from uploadFile where id="&rs1("maxid")
set rs=conn.execute(SQL)
Response.BinaryWrite rs("Content")
rs.close
rs1.close
conn.close 
Response.End
%>

其中,Web Server向客户端发送Content-Type="application/msword",使客户端认为这是Word文档,然后服务器从数据库中读取文件内容(为简单起见,假定是数据库中最后一条记录),然后以二进制流的方式向客户端发送(调用ASP内置对象Response的BinaryWrite方法)。当客户端接收到这些内容后便自动启动Word OLE服务,使Word控件嵌在浏览器IE中将收到的内容格式化显示。

标签:ASPupload,上传,组件
0
投稿

猜你喜欢

  • 服务端XMLHTTP(ServerXMLHTTP in ASP)进阶应用-User Agent伪装

    2008-11-11 12:29:00
  • 使用 TRUNCATE TABLE 删除所有行

    2008-04-24 19:20:00
  • 使用:after清除浮动

    2008-10-30 12:10:00
  • 启发式评估(heuristic evaluation)

    2009-08-27 13:03:00
  • IE7新支持的CSS属性和属性选择符

    2008-03-16 14:26:00
  • 如何绕过ODBC直接访问SQL Server?

    2010-05-18 18:13:00
  • Dreamweaver技巧50问

    2008-10-16 14:00:00
  • css表单中textarea域背景图片设置方法

    2008-04-21 13:56:00
  • 如何取得刚添加的记录自动增加的ID?

    2010-01-18 20:55:00
  • ASP3.0中的流控制能力

    2008-10-19 17:41:00
  • 关于document.createDocumentFragment()

    2009-04-05 16:04:00
  • 优化SQL Server的内存占用之执行缓存

    2012-04-13 11:45:06
  • 长文章自动分页asp实例-支持HTML

    2007-10-10 21:29:00
  • Chrome和firefox使用比较测评

    2010-03-26 12:13:00
  • 专家教你安装 MySQL的与MySQL GUI Tools

    2012-01-29 17:59:05
  • 用ASP编程实现网络内容快速查找

    2007-09-16 17:56:00
  • msxml3.dll 错误 '800c0005'终极解决办法

    2009-10-05 18:40:00
  • 来看看如何防止采集

    2007-08-19 20:11:00
  • jQuery选择器 学习总结

    2008-06-15 15:41:00
  • js打开新窗口方法代码收集

    2007-09-05 19:20:00
  • asp之家 网络编程 m.aspxhome.com