aspSmartUpload 3.3 by http://www.aspsmart.com
aspSmartUpload 是一個知名的免費套件,用於微軟 IIS 系列伺服主機,提供上傳檔案介界。目前版本為 3.3 已經支援 Windows 2003 Server。 安裝及使用方式,請參閱aspSmartUpload 的安裝與使用
先來試試這裡的上傳,看能不能上傳中文檔名:
如果成功了,繼續看下去,首先,不管是不是中文檔名,都能上傳,只不過在存檔時,由於解析中文字的問題,產生了一些不正確的字元,無法存檔,所以造成錯誤,因此,在表單上稍作變動,如下:
| <input name="FILE1" type="file" id="FILE1" onblur=" this.form.H1.value=this.value.substr(this.value.lastIndexOf('\\')+1); this.form.action='upload.asp?H1='+this.form.H1.value; "/> <input name="H1" type="hidden" id="H1" /> <input type="submit" name="btn" value="上傳" /> |
在本例中,用了隱藏欄位H1,同時,當使用者選好檔案後,自動把檔名建立到H1之中,例如:檔名是「c:\卜維丰.jpg」那麼H1的值就變成「卜維丰.jpg」
接下來,執行上傳,幾個地方要注意,先看程式:
|
<% filename=Request.QueryString("H1") '宣告變數 '建立 aspSmartUpload 物件 mySmartUpload.MaxFileSize = 10000000 '執行上傳 mySmartUpload.Files.Item(1).SaveAs("/Blog/asp/temp/123.jpg") Response.Write(filename & " file(s) uploaded.") %> |
紅字的地方,就是要注意的地方,首先,Response.Charset必需和前一頁的編碼方式吻合,以本站來說,使用utf-8編碼,所以這裡也是使用utf-8編碼。
其次,第二段紅字,先把檔案以英文或數字存檔,這個例子存檔檔名叫 123.jpg ,存檔完成後,再將 123.jpg 複製成應有的檔名,而中文檔名怎麼來的呢?看藍字部份,藍字部份,和表單頁對應,在表單頁,傳送前,先把檔名用字串方式帶入上傳程式中,如此一來,就不會受到 multipart/form-data 影響,而可以用 Request.QueryString 取得正確中文字。
最後,把 123.jpg 刪除即可。
原本,把 123.jpg 更名即可,但實作上,更名也有亂碼問題,但在 big5 編碼模式下似乎又沒太大問題,我也沒仔細繼續研究,有心得的網友,別忘留言。
卜維丰 2/16 07'
同意轉載,不過麻煩看一下轉載需知
添加搜藏
petra 2010/2/10 下午 01:38:00
onblur=" this.form.H1.value=this.value.substr(this.value.lastIndexOf('\\')+1); this.form.action='upload.asp?H1='+this.form.H1.value;
請問一下,使用上面那一段放在function裡面為什麼就會說this.form的值是空的,而且才點選「瀏覽」的按鈕,就觸發事件了?
卜維丰 2010/2/5 上午 11:02:00
diamond, 該 dll 再調一下權限, 加入 IUSR_電腦名稱 這個使用者, 並開放權限
另外, 去找我 ASP 分類, 裡面有一個 ABC UPLOAD 更強大好用, 而且開放免費申請(正版的喔)
diamond 2010/2/4 下午 08:58:00
卜維丰大哥您好:
我在server 2008上都無權限上的問題,但只要元件裝在server03 or xp pro都會顯示這樣的問題,並且小弟已經把aspSmartUploadUtil.dll的權限目錄,everyone調過還是不行,顯示錯誤碼為下:
錯誤類型:
伺服器物件, ASP 0178 (0x80070005)
當檢查使用權限時 Server.CreateObject 的呼叫失敗。拒絕存取此物件。
請多指教
ATAT 2010/1/26 下午 05:51:00
不好意思 再補充一個問題
試了很多次實在不知道
要怎麼把asp的urlencode函數運用進去
讓"丟到url上帶參數前做urlencode處理"
我採用的urldecode來自於
http://blog.blueshop.com.tw/hammerchou/archive/2006/05/09/23384.aspx
但使用的時候要自行把 程式碼中
.Charset = "Big5" 改成 UTF-8
感謝再三
ATAT 2010/1/26 下午 04:43:00
發生了需要一次上傳多筆資料的狀況
有空的話...
拜託您了
celeste 2010/1/13 下午 04:00:00
您好 參考了您的資料
不過最後還是出現了亂碼的問題
但最後找到的解決方法是…
在丟到url上帶參數前 必須先將參數做URLEncode處理
從url抓下來後 必須再decode才會是正確的中文編碼哦!
也是研究了好一陣子 現在發現這個結果^^
也分享給大家!
謝謝啦!
Tsai 2009/3/10 下午 07:18:00
卜大您好,
現在 http://www.aspsmart.com 網站好像不見了, 因目前急需在 windows server 2003 上測試。不知卜大是否方便提供3.3版給我嗎? 多謝,感激不盡^^。我的email:rmotsai@yahoo.com.tw
Randy 2009/2/17 下午 05:10:00
卜大您好,
請問這個作法在aspsmartupload 3.0也適用嗎? http://www.aspsmart.com 網站好像不見了, 都找不到可以下載3.3版的站台, 還是卜大方便提供3.3版給我嗎? 我的email:rahu82@gmail.com
卜維丰 2008/11/28 下午 06:38:00
Power,
I think you could read Chinese, so I reply as...
這個例子,一次上傳一個,所以當然會連同問號一起加入,多個檔案上傳時,onBlur 中就不再執行改變 action 的動作,而是把「上傳」按鈕改為 button 型式,執行上傳前,把 action 統一調整。
需要我簡單寫個範例,再留話,不過比較對各位抱歉的,最近真的忙,經常一整天沒和我電腦親近,難免回覆慢點,見諒
Power 2008/11/25 下午 03:52:00
Just Wondering, if you have more than one files, each time onBlur, the this.form.action is reset to such as .asp?H1=?? or .asp?H2=?? or .asp?H3=??
instead of .asp?H1=??&H2=??&H3=??....
If so, how do I retrieve querystring accordingly, if the only querystring sent was the latest one.
Lee Huang 2008/9/4 下午 02:46:00
Thanks for the reply and I am still having trouble with the request.querystring. Please take a look and see if I done anything wrong. Its a Loop with iBrowse from 1 to 10 to create input dynamically:
"<INPUT TYPE='FILE' NAME='FILE"&iBrowse&"' onBlur=""this.form.H"&iBrowse&".value=this.value.substr(this.value.lastIndexOf('\\')+1); this.form.action='thispage.asp?H" & iBrowse & "='" & "+this.form.H" & iBrowse & ".value;"" /><input name='H"&iBrowse&"' type='hidden' id='H"&iBrowse&"' />"
Also, I am wondering in the loop how would each input retrieve the input value since each selection, querystring will change holding only the latest value.
Hope I am not being too confusing
卜維丰 2008/9/3 下午 03:25:00
Lee Huang,
please notice the file field named "FILE1", it means there will be anther file field such lke FILE2,FILE3 etc...
So, in client side , just copy the same syntax from FILE1 to FILE# , and in the server side using FOR..NEXT loop to execute uploading work, it looks like ...
FOR I= 1 to #
filename=Request.QueryString("H"&I)
......
NEXT
Please notice the sample I wrote above (red chars)
mySmartUpload.Files.Item(1).SaveAs("/Blog/asp/temp/123.jpg")
.Item(1) <-- here contain number "1" , so you could change this to I~~^^
Good Luck
Lee Huang 2008/9/3 下午 01:10:00
TO 卜維丰:
thanks for the script, I am wondering how the code should be changed if want to upload multiple files such as
FILE1
FILE2
FILE3
FILE4
Dynamically to upate Big5 Name
Thanks
小魚兒 2007/6/6 下午 09:29:00
您好:
非常感謝您的熱心解答,問題已解決了!謝謝!
卜維丰 2007/6/6 上午 10:47:00
你這段程式我有點看不懂
For each file In mySmartUpload.Files
mySmartUpload.Form(name) <--看不懂
If not file.IsMissing Then
oRs.AddNew
file.FileToField oRs.Fields("FileName") <--看不懂
oRs("Title") = file.FileName
oRs("name") =Request("name")
oRs.Update
intCount = intCount + 1
End If
Next
是我的話, 會寫成
For each file In mySmartUpload.Files
If not file.IsMissing Then
oRs.AddNew
oRs("Title") = file.FileName
oRs("name") =mySmartUpload.Form("name")
oRs.Update
End If
Next
小魚兒 2007/6/6 上午 07:48:00
您好:
我想說把 oRs("name") =Request("name")改成oRs("name") = mySmartUpload.Form(name)可是還是沒有將name一併存入資料庫,還是得再拜託您。感謝!
小魚兒 2007/6/6 上午 07:41:00
您好:
我還是做不出來想請您再教導我看那裡該改!謝謝!
strSQL = "SELECT Title,FileName,name FROM upload"
Set oRs = Server.CreateObject("ADODB.recordset")
Set oRs.ActiveConnection = oConn
oRs.Source = strSQL
oRs.LockType = 3
oRs.Open
For each file In mySmartUpload.Files
mySmartUpload.Form(name)
If not file.IsMissing Then
oRs.AddNew
file.FileToField oRs.Fields("FileName")
oRs("Title") = file.FileName
oRs("name") =Request("name")
oRs.Update
intCount = intCount + 1
End If
Next
mySmartUpload.Files.Item(1).SaveAs("/upload/images/123.jpg")
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile Server.MapPath("/upload/images/123.jpg"), savefilename
fso.DeleteFile Server.MapPath("/upload/images/123.jpg")
Set fso=Nothing
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
intCount = mySmartUpload.Save("/upload/images")
Response.Write(intCount & " file(s) uploaded.")
另外,我不想把問題給撤了!這樣我才可以到那裡都可以很快找到這個網站
卜維丰 2007/6/6 上午 12:51:00
小魚兒, aspSmartUpload 的表單使用方式
如果你的上傳物件是這麼定義
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
那表單資料就變成
mySmartUpload.Form("欄位")
也就是,原本 Request.Form 改成 Set mySmartUpload.Form
另外,拿最佳解答本來就不是我上知識+的目的
看你要把問題撤了,或是自己選最佳解答吧
小魚兒 2007/6/5 上午 09:40:00
您好:
要上傳表單要看 sample5.asp 裡面有很清楚的範例,這個範例我有看只是在加入資料庫時不知道如何加入,因為它只是show出其它表單資料,並沒有教如何加入資料庫,而在sample4.asp只教存入所上傳之檔案,目前我只能利用sample1.asp及sample4.asp做成檔案上傳後存入資料夾並存入資料庫,接下去要抓表單上的資料存入資料庫就做不到,如果是用一般的手法,我是直接用sql語法insert但是這個我就不是很清楚該如何做了?
還有一件事想麻煩您,就是我的知識+發問期限快到了,一直在接受您的教導,想要選您為最佳解答,但是您是在意見的地方發表,所以我沒辦法選您為最佳解答,能請您到回答區回答,好方便我選您為最佳解答,至餘將表單其它資料上傳到資料庫的問題我可以到您的網站再求救,或是您到我的發問區再做意見發表。謝謝!
卜維丰 2007/6/4 上午 12:16:00
小魚兒,如果你是租用主機空間, 就要先問問對方
有沒有提供上傳元件
據我知道, 智X 是提供 aspSmartUpload
戰X策是提供 aspUpload
租的主機, 你沒法在上面註冊新的元件
如果是你的主機, 愛怎麼裝就怎麼裝
另外, aspSmartUpload 要上傳表單
要看 sample5.asp 裡面有很清楚的範例
先去看看, 有問題再討論
小魚兒 2007/6/3 下午 04:46:00
您好:
對不起!還有一點要請教:
傳來的表單除了上傳檔案還有其他,如文字檔位要怎麼一併存入資料庫裏?
小魚兒 2007/6/3 下午 03:19:00
您好:
不好意思我現在知道這個錯在哪裡了!因為我Sample1.htm忘了改程式,已經解決了!感謝!
能再請教這個上傳元件都要先有登錄動作,那如果我要上傳到別人的網域空間它又沒有這個動作,會不會就沒有辦法上傳檔案?
卜維丰 2007/6/3 上午 09:21:00
404 就是路徑不對
把你上傳的程式貼出來我看看
小魚兒 2007/6/3 上午 08:31:00
您好:
中文檔名解決方案,我有跟著作看看,結果出現HTTP 404 - 找不到檔案
Internet Information Services
網址列:http://localhost/upload/upload.asp?H1=測試.jpg
我將/Blog/asp/temp改成/upload/images結果就出現這種情形,能再請教這個該怎麼辦?感謝!
卜維丰 2007/5/22 下午 10:30:00
喔? 這個作法, 我在 IE 測試過
有沒有測試站, 我試試
engine 2007/5/22 上午 11:26:00
我測試從本機上傳 連結帶有中文
在firefox下是可以正常作動的
但在ie上會有問題
這似乎是ie本身的問題
![]()