?? njj_pic_upfile.asp
字號:
<!--#include file="admin_check.asp"-->
<%dim dbpath
dbpath="../"
%>
<!--#include file="../Conn.asp"-->
<!--#include file="Upload.inc"-->
<link rel="stylesheet" href="style.css" type="text/css">
<script language="JavaScript">
<!-- Hide from older browsers...
//Function to add pic
function Addpic(imagePath){
window.opener.frames.message.focus();
window.opener.frames.message.document.execCommand('InsertImage', false, imagePath);
window.close();
}
// -->
</script>
<%
dim url,a,b,c,d,x,url1,e
url=Request.ServerVariables("SERVER_NAME")&Request.ServerVariables("PATH_INFO")
dim dirnow
dirnow=split(url,"/")
a=dirnow(ubound(dirnow))
e=dirnow((ubound(dirnow)-1))
url1="http://"&Request.ServerVariables("SERVER_NAME")&Request.ServerVariables("PATH_INFO")
c=len(url1)-len(a)-len(e)-1
d=left(url1,c)
Sfileup="300‖jpg,bmp,gif,png,jpeg"
Sfileups=split(Sfileup,"‖")
filesize=Sfileups(0)
Server.ScriptTimeOut=5000
response.Buffer=true
FormPath="../uploadpic/"
call Upload_0()
Sub Upload_0()
Set Upload = New UpFile_Class ''建立上傳對象
Upload.InceptFileType = Fileli(Sfileups(1)) '上傳類型限制
Upload.MaxSize = Int(filesize)*1024 '限制大小
Upload.GetDate() '取得上傳數據
If Upload.Err > 0 Then
Select Case Upload.Err
Case 1 : Response.Write "請先選擇你要上傳的文件 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
Case 2 : Response.Write "圖片大小超過了限制"&filesize&"k [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
Case 3 : Response.Write "所上傳類型不正確 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
End Select
Exit Sub
Else
Fname=Upload.Form("Fname")
flag=Upload.Form("flag")
For Each FormName in Upload.file ''列出所有上傳了的文件
Set File = Upload.File(FormName) ''生成一個文件對象
If File.Filesize<10 Then
Response.Write "請先選擇你要上傳的圖片 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
Exit Sub
End If
FileExt = FixName(File.FileExt)
If Not ( CheckFileExt(FileExt) and CheckFileType(File.FileType) ) Then
Response.Write "文件格式不正確 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]"
Exit Sub
End If
Filenamelong=UserFaceName(FileExt)
FileName=FormPath&Filenamelong
If File.FileSize>0 Then ''如果 FileSize > 0 說明有文件數據
File.SaveToFile Server.mappath(FileName) ''保存文件
if flag="c2" then
response.write "<center><FIELDSET align=center><LEGEND align=center><font color=red>文件上傳成功 </font></LEGEND><br>[ <a href=# onclick=""Addpic('"&d&"uploadpic/"&Filenamelong&"')"">點擊這里添加到編輯器中</a> ]</fieldset>"
response.end
else
'釋放上傳對象
response.write "<script>opener.document.form1."&Fname&".value='"&Filenamelong&"'</script>"
response.write "<script>alert(""圖片上傳成功!"");window.close();</script>"
response.end
response.Write("<br>總數據量沒超過限制,文件類型正確,沒有異常,文件上傳成功.")
end if
Response.Write "圖片上傳成功!"
End If
Set File=Nothing
Next
End If
Set Upload=Nothing
End Sub
'判斷文件類型是否合格
Private Function CheckFileExt(FileExt)
Dim ForumUpload,i
ForumUpload=Fileli(Sfileups(1))
ForumUpload=Split(ForumUpload,",")
CheckFileExt=False
For i=0 to UBound(ForumUpload)
If LCase(FileExt)=Lcase(Trim(ForumUpload(i))) Then
CheckFileExt=True
Exit Function
End If
Next
End Function
'格式后綴
Function FixName(UpFileExt)
If IsEmpty(UpFileExt) Then Exit Function
FixName = Lcase(UpFileExt)
FixName = Replace(FixName,Chr(0),"")
FixName = Replace(FixName,".","")
FixName = Replace(FixName,"asp","")
FixName = Replace(FixName,"asa","")
FixName = Replace(FixName,"aspx","")
FixName = Replace(FixName,"cer","")
FixName = Replace(FixName,"cdx","")
FixName = Replace(FixName,"htr","")
End Function
'文件Content-Type判斷
Private Function CheckFileType(FileType)
CheckFileType = False
If Left(Cstr(Lcase(Trim(FileType))),6)="image/" Then CheckFileType = True
End Function
'文件名明名
Private Function UserFaceName(FileExt)
Dim UserID,RanNum
'UserID = ""
'If Dvbbs.UserID>0 Then UserID = Dvbbs.UserID&"_"
Randomize
RanNum = Int(90000*rnd)+10000
UserFaceName = UserID&Year(now)&Month(now)&Day(now)&Hour(now)&Minute(now)&Second(now)&RanNum&"."&FileExt
End Function
Function Fileli(b)
a=split(b,",")
Fileli=""
for i=0 to UBound(a)
c=trim(a(i))
Fileli=Fileli&","&c
next
End Function
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -