?? upfile.asp
字號:
<!--#include file="conn.asp"-->
<!--#include file="upload.inc"-->
<html>
<head>
<STYLE>TD {
FONT-SIZE: 9pt; LINE-HEIGHT: 140%
}
BODY {
FONT-SIZE: 9pt; LINE-HEIGHT: 140%
}
A:link {
COLOR: #0033cc; TEXT-DECORATION: none
}
A:visited {
COLOR: #0033cc; TEXT-DECORATION: none
}
A:active {
COLOR: #ff0000; TEXT-DECORATION: none
}
A:hover {
COLOR: #000000; TEXT-DECORATION: underline
}
</STYLE>
<title>資料上傳</title>
</head>
<body text=#000000 bgColor=#ffffff leftMargin=0 topMargin=0>
<table width=100% border=0 cellspacing="0" cellpadding="0"><tr><td>
<script>
parent.document.forms[0].submit.disabled=false;
</script>
<%
Server.ScriptTimeOut=999999
dim upload_type
dim upload,file,formName,filename,fileExt
dim ranNum
sql="select * from config"
set rs = server.createobject("adodb.recordset")
rs.open sql,conn,1,1
upload_type=rs("upload_type")
upload_size=rs("upload_size")
filetype=rs("upload_filetype")
rs.close
set rs = nothing
if upload_type<>0 and upload_type<>1 and upload_type<>2 and upload_type<>3 then
upload_type=0
end if
if upload_size<1 then
upload_size=1
end if
if filetype="" then
filetype="htw,ida,idq,asp,cdx,asa,htr,idc,shtm,shtml,stm,php,php3,aspx"
end if
select case upload_type
case 0
call upload_0()
case 1
call upload_1()
case 2
call upload_2()
case else
conn.close
set conn = nothing
response.write "管理員已將上傳功能關閉"
response.end
end select
'判斷資料類型是否符合要求
Private Function CheckFileExt (fileEXT)
filetype=split(filetype,",")
for i=0 to ubound(filetype)
if lcase(fileEXT)=lcase(trim(filetype(i))) then
CheckFileExt=false
exit Function
else
CheckFileExt=true
end if
next
End Function
'===========無組件上傳(upload_0)====================
sub upload_0()
set upload=new UpFile_Class ''建立上傳對象
upload.GetDate (upload_size*1024) '取得上傳數據
if upload.err > 0 then
select case upload.err
case 1
Response.Write "請首先選擇您要上傳的資料 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
case 2
Response.Write "資料太大,請壓縮后再上傳(資料大小不得超過"&upload_size&"K) [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
end select
set upload=nothing
exit sub
else
for each formName in upload.file ''列出所有上傳了的資料
set file=upload.file(formName) ''生成一個資料對象
fileExt=lcase(file.FileExt)
'判斷資料類型
if CheckFileExt(fileEXT)=false then
set upload = nothing
set file = nothing
response.write "管理員禁止上傳該類型資料,請打包或修改擴展名后再上傳 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
exit sub
end if
randomize
ranNum=int(90000*rnd)+10000
filename="files/"&session("teacherid")&"at"&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
if file.FileSize>0 then ''如果 FileSize > 0 說明有資料數據
file.SaveToFile Server.mappath(filename) ''保存資料
response.write "上傳成功!"
response.write "<script>parent.document.forms[0].fileurl.value='"&FileName&"'</script>"
else
Response.Write "不得上傳大小為0的資料 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
end if
set file=nothing
next
set upload=nothing
end if
end sub
'===========Lyfupload組件上傳(upload_1)=========================
sub upload_1()
dim obj,filename,fileExt_a
dim ss
Set obj = Server.CreateObject("LyfUpload.UploadFile")
'資料大小限制
obj.maxsize=upload_size*1024
if obj.request("fname")="" or isnull(obj.request("fname")) then
Response.Write "請首先選擇您要上傳的資料 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
exit sub
end if
randomize
ranNum=int(90000*rnd)+10000
fileExt_a=split(obj.request("fname"),".")
fileExt=lcase(fileExt_a(ubound(fileExt_a)))
if CheckFileExt(fileEXT)=false then
set obj = nothing
response.write "管理員禁止上傳該類型資料,請打包或修改擴展名后再上傳 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
exit sub
end if
filename=session("teacherid")&"at"&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
filename=filename&"."&fileExt
ss=obj.SaveFile("file1",Server.MapPath("files/"), true,filename)
if ss= "3" then
Response.Write ("資料名重復! [ <a href=# onclick=history.go(-1)>重新上傳</a> ]")
set obj=nothing
exit sub
elseif ss= "0" then
Response.Write ("資料太大,請壓縮后再上傳(資料大小不得超過"&upload_size&"K) [ <a href=# onclick=history.go(-1)>重新上傳</a> ]")
set obj=nothing
exit sub
elseif ss = "" then
Response.Write ("上傳失敗! [ <a href=# onclick=history.go(-1)>重新上傳</a> ]")
exit sub
else
Response.Write "上傳成功!"
response.write "<script>parent.document.forms[0].fileurl.value='files/"&filename & "'</script>"
set obj=nothing
exit sub
end if
end sub
''===========================Aspupload3.0組件上傳============================
sub upload_2()
dim Count
on error resume next
Set Upload = Server.CreateObject("Persits.Upload")
Upload.OverwriteFiles = false '不允許覆蓋重名資料
Upload.IgnoreNoPost = True
Upload.SetMaxSize upload_size*1024, True '資料大小限制
Count = Upload.Save
If Err.Number = 8 Then
Response.Write "資料太大,請壓縮后再上傳(資料大小不得超過"&upload_size&"K) [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
Else
If Err <> 0 Then
Response.Write "錯誤信息: " & Err.Description
Else
If Count < 1 Then
Response.Write "請首先選擇你要上傳的資料 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
set Upload =nothing
exit sub
End If
For Each file in Upload.Files '列出所有上傳資料
fileExt=lcase(replace(File.ext,".",""))
'判斷資料類型
if CheckFileExt(fileEXT)=false then
set upload = nothing
response.write "管理員禁止上傳該類型資料,請打包或修改擴展名后再上傳 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
exit sub
end if
'資料變量付值
randomize
ranNum=int(90000*rnd)+10000
filename=session("teacherid")&"at"&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&File.ext
filename="files/"&filename
file.saveas Server.MapPath(filename) '上傳保存資料
response.Write "上傳成功!"
response.write "<script>parent.document.forms[0].fileurl.value='" &filename& "'</script>"
Next
End If
End If
set Upload = nothing
end sub
conn.close
set conn = nothing
%>
</td></tr></table>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -