熱點問題


推薦產(chǎn)品
- 300M國內(nèi)免備案空間
300M網(wǎng)站空間,送60M數(shù)據(jù)庫!
現(xiàn)價只要:22元/月 - 500M國內(nèi)免備案空間
500M網(wǎng)站空間,送100M數(shù)據(jù)庫!
現(xiàn)價只要:29元/月 - 1G國內(nèi)免備案空間
1G網(wǎng)站空間,送300M數(shù)據(jù)庫!
現(xiàn)價只要:39元/月 - 500M香港免備案空間
500M網(wǎng)站空間,送160M數(shù)據(jù)庫!
現(xiàn)價只要:26元/月 - 1G香港免備案空間
1G網(wǎng)站空間,送300M數(shù)據(jù)庫!
現(xiàn)價只要:36元/月 - 100M美國空間
100M網(wǎng)站空間,送30M數(shù)據(jù)庫!
現(xiàn)價只要:12.8元/月

如何使用AspUpload組件上傳文件
文章來源:51網(wǎng)絡(luò)科技 點擊數(shù): 更新時間:2012/12/20 17:08:43
購買國內(nèi)免備案空間 | 購買香港空間【不限iis】 | 寬屏網(wǎng)站制作【還送手機網(wǎng)站】 |
香港云主機/99元/月 | 國內(nèi)空間【免費備案】 | 特價網(wǎng)站空間 |
.Net專用空間 | 網(wǎng)站快速排名 | 游戲空間【支持月付】 |
使用AspUpload組件上傳文件,使用范例代碼如下:
AspUpload組件上傳測試
<form method="POST" enctype="multipart/form-data" action="?act=upload">
<input type="file" size="40" name="file1"><br>
<!--<input type="file" size="40" name="file2"><br>
<input type="file" size="40" name="file3"><br>-->
<br>其他表單項<input type="text" name="uploadText" value=""><br>
<br><input type="submit" value="上傳文件">
</form>
<%
if request("act") = "upload" then
AllowExt = "jpg,png,gif,zip,rar,sql,txt,bak"
On Error Resume Next
' 新建AspUpload對象
Set Upload = Server.CreateObject("Persits.Upload")
' 限制文件大小
Upload.SetMaxSize 4194304, True
' 上傳路徑--當前目錄下的test目錄
uploadDir = Server.MapPath("test")
' 嘗試創(chuàng)建路徑文件夾,true表示忽略目錄已存在錯誤
Upload.CreateDirectory uploadDir, true
' 先上傳文件至服務(wù)器內(nèi)存
Count = Upload.Save()
' 檢測上傳錯誤
If Err.Number = 8 Then
Response.Write chinese2unicode("錯誤: 文件過大!")
Response.end
Else
If Err <> 0 Then
response.write chinese2unicode("發(fā)生錯誤:")
response.write chinese2unicode(Err.Description)
response.end
End If
End If
'Response.Write chinese2unicode("共 " & Count & " 個文件") & "<br><br>"
' 指定一個上傳的表單文件
Set File = Upload.Files("file1")
If Not File Is Nothing Then
' 獲取原本文件名
Filename = File.Filename
' 獲取文件擴展名
Fileext = File.Ext
' 檢測文件格式是否合格
ChkStr = ","&Lcase(AllowExt)&","
If Instr(ChkStr,","&right(Fileext,3)&",") <= 0 Then
Response.Write chinese2unicode("錯誤: 文件類型不正確!")
response.write "<br>"
response.write chinese2unicode("只允許:"&AllowExt)
' 刪除內(nèi)存中的臨時文件,以釋放內(nèi)存或硬盤空間(還可用Copy、Move兩個指令)
File.Delete
' 檢測是否存在文件
elseif Upload.FileExists(uploadDir & "\\" & Filename) Then
File.SaveAs uploadDir & "\\" & Filename
Response.Write chinese2unicode("已覆蓋存在相同文件名的文件: ") & File.Path
' 保存文件
else
File.SaveAs uploadDir & "\\" & Filename
Response.Write chinese2unicode("文件已保存到: ") & File.Path
end If
Else
Response.Write chinese2unicode("錯誤: 您并沒有選擇文件!")
End If
Response.Write "<br><br>"
'' 批量上傳文件,去掉注釋即可用。
For Each File in Upload.Files
'File.SaveAs uploadDir & "\\" & File.FileName
'Response.Write chinese2unicode("文件已保存到: ") & File.Path & "<br>"
Next
'Response.Write "<br><br>Files:<br>"
For Each File in Upload.Files
'Response.Write File.Name & "= " & File.Path & " (" & File.Size &" bytes)<br>"
Next
'' 列出其他表單內(nèi)容(必須執(zhí)行Upload.Save()后才有效)
For Each Item in Upload.Form
Response.Write Item.Name & " = " & Item.Value & "<br>"
Next
'列出指定的表單內(nèi)容
Response.Write "<br>"&chinese2unicode("列出指定內(nèi)容uploadText:"&Upload.Form("uploadText").value)
end if
' gb2312轉(zhuǎn)unicode,解決中文亂碼問題
function chinese2unicode(Str)
dim i
dim Str_one
dim Str_unicode
for i=1 to len(Str)
Str_one=Mid(Str,i,1)
Str_unicode=Str_unicode&chr(38)
Str_unicode=Str_unicode&chr(35)
Str_unicode=Str_unicode&chr(120)
Str_unicode=Str_unicode& Hex(ascw(Str_one))
Str_unicode=Str_unicode&chr(59)
next
Response.Write Str_unicode
end function
%>
國內(nèi)、香港、美國、全免備案www.hnscxh.com--51網(wǎng)絡(luò)科技,專業(yè)免備案空間提供商!
本文網(wǎng)址:http://www.hnscxh.com/question_4/149.html
相關(guān)文章