<!--#include file="Inc.asp"-->
<!--#include file="ydzqpass.asp"-->
<!--#include file="upload.inc"-->

<%call head()

Call saycarda("WAP2.0上传")

set rs=server.CreateObject("adodb.recordset")
			sql="select * from twapp"
			rs.open sql,conn,1,1
Server.ScriptTimeOut=9999999
AllowFileType= ""&rs("format")&""	'允许上传的文件类型，用“,”隔开
AllowFileSize=""&rs("YD_size")&""	'最大上传文件，以KB为单位
rs.close
Set rs=nothing


	' 忽略所有错误
    'On Error Resume Next
Server.ScriptTimeOut = 1800
dim constPath,mypath
mypath=server.mappath("photo_Upfile.asp")
constPath=replace(mypath,"photo_Upfile.asp","")
dim TP
TP=request.querystring("TP")
dim upload,oFile,formName,SavePath,filename,fileExt,oFileSize,sizes
dim EnableUpload
dim arrUpFileType
dim ranNum
dim msg,FoundErr,MaxFileSize
MaxFileSize=""&bbsupsize&""'最大上传文件，以KB为单位
msg=""
FoundErr=false
EnableUpload=true
dim strMonth,strDay
dim kk,reshow,pwidth,pheight,up
dim userid,username,sessionid,photoContent,photoview

kk=0

	set upload=new upfile_class ''建立上传对象
	upload.GetData(104857000600)   '取得上传数据,限制最大上传100M
	if upload.err > 0 then  '如果出错
		select case upload.err
			case 1
				msg= "请先选择你要上传的文件！"
			case 2
				msg= "你上传的文件总大小超出了最大限制（100M）"
		end select
		'showWML()
		response.end
	end if

  SavePath = "file/"	
	photoContent=trim(upload.form("photoContent"))
	photoview=clng(upload.form("photoview"))
  'if photoContent="" then
  'Call Error("相片说明不能为空，请返回重试！")
  'end if
if len(photoContent)>30 then
  Call Error("相片说明最多30字，请返回重试！")
  end if

for each formName in upload.file 
		set ofile=upload.file(formName)  '生成一个文件对象	
		upfilename=ofile.FileName		
		oFileSize=ofile.filesize	
		sizes=cstr(round(oFileSize/1024))		
		fileExt=lcase(ofile.FileExt)
   
   voteet=split(AllowFileType,fileExt)
if ubound(voteet)=0 Then
			msg="你上传的文件不允许上传,合法的文件类型:"&AllowFileType&"...<br/>如果你上传的文件是合法的类型,但未能通过上传,那么请联系站长后台配置 ^ ^<br/><a href=""myphoto.asp?saytk="&saytk&"&amp;sid="&sid&""">返回相册</a><br/>"
			response.write msg
             call head1()
		  response.end
		end If	
if fileExt="gif" or fileExt="jpg" or fileExt="jpeg" or fileExt="png" or fileExt="bmp" then
else
 
Call Error("图片格式错误！只允许上传gif,png,jpg,jpeg,bmp类型图片")
end if

		if oFileSize>(photoSize*1024) then
      msg="文件大小超过了限制，最大只能上传" & CStr(photoSize) & "K的文件！"
			FoundErr=true
			'showWML()
call headsay()
		  response.end
		end if
		
		
		if FoundErr<>true then
			randomize
			ranNum=int(900*rnd)+100
			
			strMonth=month(now)
			if len(strMonth)=1 then
				strMonth="0"&strMonth
			end if
			strDay=day(now)
			if len(strDay)=1 then
				strDay="0"&strDay
			end if
			
			'--------------------
			
			filename=SavePath&year(now)&strMonth&strDay&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
      'response.write getRealPath(FileName)
      dim realpath
      realpath=getRealPath(filename)
      ' response.write realpath
      '建立文件夹
      setCreateFolder(realpath)
			
			ofile.SaveToFile Server.mappath(realpath)   '保存文件   
    
      
      if upfilename<>"" then
		  '将文件写入数据库
			 dim intsql,tempcontent 
       intsql= "insert into upfile(username,fid,format,YD_size,files)values"
       intsql= intsql & "('" & myni& "',"&myid&",'" & fileExt & "','" & sizes & "','" & realpath & "')"
       conn.execute(intsql)

	
'--------看空间支持与否------------		
dim wi,hi,w,h,hhi
'命名方式
dim photoname,ranNums
randomize
ranNums=int(90000*rnd)+10000
photoname=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNums&"."&fileExt
        w=60 '定义相册的列表缩略图的大小,以宽为标准
                dim j
		set j=server.createobject("persits.jpeg")
		j.open server.mappath(realpath)
		wi=j.width
		hi=j.height
if wi>W then 
hhi=wi/W
               j.width=w
               j.height=w+5
end if
		j.save server.mappath("photo/"&photoname)
		j.close
		set j=nothing
dim upfileid
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select top 1 ID from upfile order by id desc",conn,1,1
upfileid=rs("ID")
rs.close
set rs=nothing
 '将文件写入数据库
	
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select smallfiles,smallstr,filesname,photoContent,photoview from upfile where id="&upfileid,conn,1,2
if not rs.eof then
         rs("smallfiles")="photo/"&photoname
         rs("filesname")=upfilename
         rs("photoContent")=photoContent
         rs("photoview")=photoview
         rs("smallstr")=1
         rs.update
        end if
       rs.close
  set rs=nothing
       
'--------看空间支持与否------------	
	END IF
	END IF
		set file=nothing
	
next
    
	set upload=nothing

IF TP<>"" then
conn.Execute("update users set photo='"&realpath&"' where id="&myid)
	    msg="您的头像已成功上传！<br/><a href=""show.asp?saytk="&saytk&"&amp;sid="&sid&""">我的空间</a><br/>"
else
	    msg="您的相片已成功上传！<br/><a href=""photo.asp?saytk="&saytk&"&amp;sid="&sid&""">我的相册</a><br/>"
end if
		 conn.close
set conn=nothing
			

%>
<%=msg%><br/>
当前略缩图大小:<%=w%><br/>
<a href="index.asp?sid=<%=sid%>&saytk=<%=saytk%>">社区首页</a><br/>

<%
 call headsay()

%>

