<% option explicit %>
<% response.buffer=true %>
<% 'On Error Resume Next %>
<!--#include file="functions.asp"-->
<%
Dim T_R,T_G,T_B,temp
randomize
T_R=Hex(int(rnd*(255-0+1)+0))
T_G=Hex(int(rnd*(255-0+1)+0))
T_B=Hex(int(rnd*(255-0+1)+0))
Response.write temp
%>
<body bgcolor=#<%=T_R&T_G&T_B%>>
<TABLE class=tborder cellSpacing=1 cellPadding=6 width="50%" border=0 height="73">
<TBODY><TR><TD height="71" vAlign=top class=alt1><table width="96%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top">
<%
Dim ExtName,UpLoadAll_a,FormStream_h,UploadStream_c,FormDataAll_d
Dim CrLf_e,FormStart_f,FormEnd_g,FormStreamText_i,FileName_j,SavePath
Dim FileType,i,SaveFile,k,L,SaveFileName,Saver
ExtName = "jpg,gif,bmp,txt,xls,doc,rar,asp,kmz,mp4,ppt"    '*****************允许扩展名
UpLoadAll_a = Request.TotalBytes '*********************************取得客户端全部内容的长度
If(UpLoadAll_a>0) Then
if UpLoadAll_a>50000000 then
Response.write "File too big, Forbided<br>"
Response.write "File should small than 47.7MB<br>"
Response.write "<input type=""button"" value=""Back"" onclick =""location.href='uploadimg.asp'"" width:120"">"
Response.write" <meta http-equiv='Refresh' content='4;URL=uploadimg.asp'> "
Response.End
End if
Set UploadStream_c = Server.CreateObject("ADODB.Stream")
UploadStream_c.Type = 1
UploadStream_c.Open
UploadStream_c.Write Request.BinaryRead(UpLoadAll_a)
UploadStream_c.Position = 0
FormDataAll_d = UploadStream_c.Read
CrLf_e = chrB(13)&chrB(10)
FormStart_f = InStrB(FormDataAll_d,CrLf_e)
FormEnd_g = InStrB(FormStart_f+1,FormDataAll_d,CrLf_e)
Set FormStream_h = Server.Createobject("ADODB.Stream")
FormStream_h.Type = 1
FormStream_h.Open
UploadStream_c.Position = FormStart_f + 1
UploadStream_c.CopyTo FormStream_h,FormEnd_g-FormStart_f-3
FormStream_h.Position = 0
FormStream_h.Type = 2
asp资讯网站源码FormStream_h.CharSet = "GB2312"
FormStreamText_i = FormStream_h.Readtext
FormStream_h.Close
FileName_j = Mid(FormStreamText_i,InstrRev(FormStreamText_i,"\")+1,FormEnd_g)
Select Case UCase(right(FileName_j,4))  '**************************保存路径
Case ".ASP", ".ASA", "ASPX", "ASAX", ".MDB"
Response.Write "禁止上传!"
Response.End
Case ".XLS",".DOC",".RAR",".TXT",".PPT"
SavePath = "doc"
Case ".JPG",".GIF",".BMP"
if len(FileName_j)=15 then
FileName_j=left(FileName_j,Len(FileName_j)-4)&".jpg"
SavePath = "pic"
else
SavePath = "Upload"
End if
Case else
SavePath = "file"
End Select
If Right(SavePath,1) <>"/" Then SavePath=SavePath&"/" '***********************在目录后加(/)
CheckAndCreateFolder(SavePath)
If(CheckFileExt(FileName_j,ExtName)) Then
SaveFile = Server.MapPath(SavePath & FileName_j)
If Err Then
Response.Write "文件上传: <span color:red;"">文件上传出错! </span>  <a href=""" & Request.ServerVariables("URL") &""">重新上传文件 </a> <br />"
Err.Clear
Else
T_G = ReNameExists(SaveFile)'***************************重命名以后的文件
k=Instrb(FormDataAll_d,CrLf_e&CrLf_e)+4
l=Instrb(k+1,FormDataAll_d,leftB(FormDataAll_d,FormStart_f-1))-k-2
FormStream_h.Type=1
FormStream_h.Open
UploadStream_c.Position=k-1
UploadStream_c.CopyTo FormStream_h,l
FormStream_h.SaveToFile SaveFile,2
SaveFileName = Mid(SaveFile,InstrRev(SaveFile,"\")+1)
Saver=SaveFileName
if UCase(right(FileName_j,4))<>".GIF" and UCase(right(FileName_j,4))<>".BMP" and UCase(right(FileName_j,4))<>".JPG" then
T_R="'"&Session("UserName")&"','"&Now()&"','"&T_G&"','"&SavePath&"','"&Session("UserName")&"'"
T_G="UPUser,Timed,FName,SFPath,Loader"
T_B=AddRecord("FileManage",T_G,T_R)
End if
Response.write "文件<span color:red;"">" & Saver & " </span>上传成功!<a href=""" & Request.ServerVariables("URL") &""">继续上传文件 </a> <br/>"
Response.write "请及时去""文件管理""页面设置您的访问权限,例如:设置什么人可以下载您上传的文件 "
temp=AddRecord("trace","Name,Timed,Operation","'"&Session("UserName")&"','"&Now()&"','上传名称为"&Saver&"的文件到"&SavePath&"'")
%>
<%
if UCase(right(FileName_j,4))=".GIF" or UCase(right(FileName_j,4))=".JPG" or UCase(right(FileName_j,4))=".BMP" then
%>
<div id="layer1">
<p><img border="0" src="<%=SavePath%>/<%=Saver%>" height="176" title="图片预览"></div>
<%
End if
%>
<%
End If
Else
Response.write "文件<span color:red;"">格式不正确!</span><a href=""" & Request.ServerVariables("URL") &""">重新上传文件 </a> <br />"
End If
Else
%>
<script language="Javascript">
<!--
function ValidInput()
{   
if(document.upform.upfile.value=="")
{
alert("请选择上传文件!")
document.upform.upfile.focus()
return false
}
return true
}
// -->
</script>
</p>
<form action='<%= Request.ServerVariables("URL") %>' method='post' name="upform" onSubmit="return ValidInput()"  enctype="multipart/form-data" title="图片尺寸需为300*220,可以上传gif,jpg">
上传图片<input type='file' name='upfile' size="40"><input name="submit" type='submit' value="上传">
</form>             
<%
End if
Set FormStream_h = Nothing
%>
</td></tr></table></TD></TR></TBODY></TABLE></body>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。