aspupload檔案重新命名及上傳進度條的解決方案附代碼第1/2頁

來源:互聯網
上載者:User

發現還沒有aspupload這個組件的,這兩樣功能的解決方案,現把我的改進方案寫在這裡!謝謝
關於aspupload上傳組件,檔案重新命名,進度條的問題解決方案!
共用到4個檔案,分別是1.asp,2.asp,bar.asp,framebar.asp
運行第一個檔案:1.asp,執行上傳操作! 複製代碼 代碼如下:<%
'''進度條
dim SPid,PID,barref
Set UploadProgress = Server.CreateObject("Persits.UploadProgress")
SPid = UploadProgress.CreateProgressID()
PID = "PID=" & SPid
barref = "framebar.asp?to=10&" & PID
%>
<SCRIPT language="javascript">
<!--
function ShowProgress()
//載入進度條
{
strAppVersion = navigator.appVersion;
if (document.upfile.filename.value != "")
{
if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
{
winstyle = "dialogWidth=375px; dialogHeight:175px; center:yes;status:no";
window.showModelessDialog('<% = barref %>&b=IE',window,winstyle);
}
else
{
window.open('<% = barref %>&b=NN','','width=370,height=165', true);
}
}
return true;
}
function isPic(){
var temp;
var ExtList = ".jpg.gif.bmp.png.swf";//用戶端,檢測檔案尾碼名,省得上傳完成後,才報檔案類型錯誤!
var filename = upfile.filename.value;
var the_ext = filename.substr(filename.lastIndexOf(".")+1).toLowerCase();
if (ExtList.indexOf(the_ext)==-1){
alert("不是圖片,請選擇圖片檔案!");
return false;
}
return true;
}
//-->
</SCRIPT>
  <html>
  <head></head>
  <body>
  <form method="post"enctype="multipart/form-data"action="2.asp?<% = PID %>"name="upfile"OnSubmit="return ShowProgress();">
  
  選擇要上傳的檔案:<br>
  <input type=file name="filename"><br>
  <input type=submit value="上傳" onclick="return isPic()">
  </form>

  </body>
  </html>

2.asp 複製代碼 代碼如下:<%

Set Upload = Server.CreateObject("Persits.Upload")

' Prevent overwriting
Upload.OverwriteFiles = False

' We use memory uploads, 檔案大小限制 ,單位:b
Upload.SetMaxSize 1*1024*1024*1024, true

if Request.QueryString("PID") = "" then
Upload.ProgressID="010D60EB00C5AA4B"
else
Upload.ProgressID=Request.QueryString("PID")
end if

On Error Resume Next

' Save to memory 儲存到記憶體
Upload.Save

If Err.Number = 8 Then
Response.Write "檔案大於1G"
End If

'為使檔案不重名,用系統時間+隨機數,作為檔案名稱
Dim ranNum
randomize
ranNum=int(999*rnd)
CreateName=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
NewName = CreateName
'儲存檔案路徑
articlepath = Server.MapPath("upload1")

For Each File in Upload.Files
FileExt=Lcase(replace(File.ext,".",""))
'伺服器端判斷檔案類型,動網論壇的判斷方式
If CheckFileExt(FileExt)=false then
Response.write "檔案格式不正確,或不可為空 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"

else
File.SaveAs articlepath & "/" & NewName & File.ext
Response.Write "New name: " & File.FileName & "<BR>"
End If

Next

%>
<%
'伺服器端判斷檔案類型,動網論壇的判斷方式
Private Function CheckFileExt(FileExt)

If FileExt="" or IsEmpty(FileExt) Then
CheckFileExt=false
Exit Function
End If
If Lcase(FileExt)="asp" or Lcase(FileExt)="asa" or Lcase(FileExt)="aspx" then
CheckFileExt=false
Exit Function
End If
If Lcase(FileExt)="gif" or Lcase(FileExt)="jpg" or Lcase(FileExt)="png" or Lcase(FileExt)="swf" or Lcase(FileExt)="bmp" then
CheckFileExt=true
Exit Function
Else
CheckFileExt=false
End If
End Function
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.