ASP ez 2012-06-20
ASP 並沒有內建上傳元件,必須要透過第三方元件才能進行上傳,本篇利用 LyfUpload 進行上傳!
本地下載:LyfUpload v1.2
必須先註冊 LyfUpload.dll,方法如下圖:
使用方式可以參考檔案裡的範例檔案,以下僅貼出一篇範例:
demo1.htm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>LyfUpload组件</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<style></style>
</head>
<body bgcolor="#C4E0FD">
<table border="0" width="100%" bgcolor="#CBFCF4">
<tr>
<td width="50%"><font color="#ff80c0" face="Comic Sans MS"><strong>LyfUpload</strong></font>组件1.2-<strong>演示程序</strong>
2000.4.24</td>
<td width="50%">作者:<font color="#0000ff"><a href="mailto:[email protected]">刘玉锋</a></font></td>
</tr>
<tr>
<td width="50%">文件上传组件。。。</td>
<td width="50%"><font color="#000000">主页:</font><font color="#0000ff"><a
href="http://vbfans.yeah.net">VB爱好者(http://vbfans.yeah.net)</a><br>
<a href="http://aspfans.yeah.net">ASP爱好者(http://aspfans.yeah.net)</a></font></td>
</tr>
</table>
<table border="0" width="100%" bgcolor="#FDDBC4">
<tr>
<td width="44%">上传一个文件,可以混和Form中的其它元素(<font
color="#FF0000">采用不覆盖同名文件方式上载</font>)<p>默认上传到C:\temp目录,如果没有,请先建立此目录</p>
<form method="POST" enctype="multipart/form-data" action="demo1.asp">
<p>文本框1: <input type="text" name="text1" size="20"><br>
选择文件:<input type="file" name="file1"><br>
<input type="submit" value="上载"
style="background-color: rgb(0,0,255); color: rgb(255,255,0)"> </p>
</form>
</td>
</tr>
</table>
</body>
</html>demo1.asp
<%@Language=VBScript %>
<HTML>
<BODY>
<%
filename="file1"
path="c:\temp"
Set obj = Server.CreateObject("LyfUpload.UploadFile")
txt = obj.request("text1") '得到form元素的值
Response.Write( "文本框1的输入值是: " & txt)
Response.Write "<br>"
'上载后文件重命名,使用变量方式
varfname="sss.txt"
ss=obj.SaveFile(filename, path, false,varfname) '保存文件到服务器
aa=obj.filetype("file1")
if ss="3" then
Response.Write "此文件在服务器上已经存在!不能覆盖!"
elseif ss<> "" then
Response.Write "选择的文件已经上载到服务器!<br>"
Response.Write("文件名:" & ss)
Response.Write("<br>Content-Type:" & aa) '得到Content-Type
Response.Write("文件大小:" & obj.FileSize)
end if
obj.about '关于LyfUploa1.2
%>
</BODY >
</html>標籤: ASP
