=  =|||多檔上傳 

<!--#include FILE="conn.asp"-->
<!--#include FILE="upload_5xsoft.asp"-->

<%
'關掉快取資料
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"

'此函數抓取副檔名
Function GetExtendName(FileName)
Dim ExtName
ExtName = LCase(FileName)
ExtName = right(ExtName,3)
ExtName = right(ExtName,3-Instr(ExtName,"."))
GetExtendName = ExtName
End Function

file_Documents = Session("file_Documents") '設定檔案放置資料夾

FileMaxSize = 500000000 '設定檔案允許的大小
Server.ScriptTimeOut = 10000 '設定檔案傳輸時間
FileType = ".jpg.jpeg.png.gif.bmp.doc.xls.txt.zip.rar.pdf.doc.docx" '設定允許的副檔名

Dim upload,file,formName,i
Set upload = New upload_5xsoft  '建立上傳對象

'--------------------------------------------------------------------
UpFilePath = "upload/" & file_Documents
If right(UpFilePath,1) <> "/" then UpFilePath = UpFilePath & "/"
'--------------------------------------------------------------------

For Each formName in upload.file '列出所有上傳的檔案
Set file = upload.file(formName) '生成一個檔案對象

i = 0

If file.FileSize > 0 then
 If file.FileSize < FileMaxSize then
 
  If FileType <> "" then
   If Instr(FileType,GetExtendName(file.FileName)) then
    TypeFlag = 1
   Else
   TypeFlag = 0  '檔案為不允許的類型
   End If
  Else
  TypeFlag = 1   '沒有限制上傳檔案類型
  End If

'--------------------------------------------------------------------
If TypeFlag = 1 then
fname = file.FileName
file.SaveAs Server.mappath(UpFilePath&file.FileName)

'--------------------------------------------------------------------

If fname <> Empty then
'插入文字地方
'--------------------------------------------------------------------
id = session("id")
file_Documents = Session("file_Documents")
'--------------------------------------------------------------------

'新增資料到資料庫
'--------------------------------------------------------------------

Set rs=Nothing
Set rs = Server.CreateObject("ADODB.Recordset")
Sql = "insert into product_upload([gid],[filepath]) values ('"& id &"','"& fname &"')"
rs.Open Sql, Conn, 1,1
Response.Write "<p align='center' style=margin-top: 50px'><font size='2' color='#006699'>資料更新完畢...</font></p>"
Response.Write "<p align='center' style=margin-top: 50px'><a href='javascript:close();'><font size='2' color='#006699'>關閉視窗</font></a></p>"
Response.Write "<p align='center' style=margin-top: 50px'><a href='#' onClick='history.go(-1)'><font size='2' color='#006699'>返回上頁更新資料</font></a></p>"
'--------------------------------------------------------------------
Else
Response.write "Error:上傳檔案失敗,目前只允許使用"& FileType &"<br><a href='#' onClick='history.go(-1)'><font color='#336699'>返回上頁重新上傳</font></a>"
End If
i = i+1
End If
'--------------------------------------------------------------------
Set file = Nothing
 Else
 Exit For
 Set upload = Nothing
 End If
End If
Next
%>

lovean 發表在 痞客邦 PIXNET 留言(1) 人氣()


留言列表 (1)

發表留言