6行代碼實現ASP無組件上傳

來源:互聯網
上載者:User

目前有很多無組件上傳類,我大概看了一下,大多寫的相當複雜,有的居然還只能傳文本,最關鍵的是沒有10行代碼以下的:),我花了一個晚上時間研究了一下ADODB.Stream,並且用了6行代碼實現了無組件上傳:
upload.asp 檔案代碼
<%
strFileName = Request.QueryString("fn")
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary 二進位方式
objStream.Open
objStream.LoadFromFile strFileName
objStream.SaveToFile Server.MapPath("zslogo.gif"),2
%>
使用方法
在瀏覽器裡面輸入:
http://xxx/upload.asp?fn=c:/上傳檔案/123.gif
其中xxx為你的網站網域名稱地址,比如:www.jzxue.com
執行完後你會看到你的目錄下面多了一個zslogo.gif,就是你剛才上傳的檔案拉。
根據ASP無組件上傳原理,我們把上面的代碼擴充為以下代碼:
upload.asp 檔案代碼
<%
Function GetFileName(ByVal fn)
If fn<>"" Then GetFileName=mid(fn,InStrRev(fn,"/")+1) Else GetFileName=""
Endfunction

strFileName = Request.Form("file1")
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 ' adTypeBinary
objStream.Open
objStream.LoadFromFile strFileName
objStream.SaveToFile Server.MapPath(GetFileName(strFileName)),2
objStream.Close
%>
upload.htm 檔案代碼
<form name="upform" action="upload.asp" method="post" enctype="multipart/form-data">
<input type="file" name="file1" style="width:400px;" value="" />
<input type="submit" name="submit" value="上傳檔案" />
</form>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.