<!--#include file="Inc.asp"-->
<!--#include file="ydzqpass.asp"-->
<!--#include file="upload.inc"-->
<!--#include file="forbbs.asp"-->
<card id="main" title="WAP2.0上传"><p>
call head()
	' 忽略所有错误
    'On Error Resume Next
Server.ScriptTimeOut = 1800
dim constPath,mypath
mypath=server.mappath("WAP2_Upfile.asp")
constPath=replace(mypath,"WAP2_Upfile.asp","")
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 tid,action,bbsid,title,content,content1,content2,content3,content4,content5,content6,content7,content8,content9,content10
dim kk,reshow,pwidth,pheight,up
dim userid,username,sessionid
	bbsid=trim(request.querystring("bbsid"))
	tid=trim(request.querystring("tid"))
	up=trim(request.querystring("up"))
  if bbsid="" or Isnumeric(bbsid)=False then
  Call Error("ID无效！")
  end if

if up<>0 then
  if tid="" or Isnumeric(tid)=False then
  Call Error("ID无效！")
  end if
up=clng(up)
end if
kk=0

	set upload=new upfile_class ''建立上传对象
	upload.GetData(104857600)   '取得上传数据,限制最大上传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/"
  

	
	title=forbbs(upload.form("name"))
	content=forbbs(upload.form("content"))
	content=replace(content,"sid=sid","sid=@@sid@@")
	content1=forbbs(upload.form("content1"))
	content2=forbbs(upload.form("content2"))
  content3=forbbs(upload.form("content3"))
  content4=forbbs(upload.form("content4"))
  content5=forbbs(upload.form("content5"))
  content6=forbbs(upload.form("content6"))
  content7=forbbs(upload.form("content7"))
  content8=forbbs(upload.form("content8"))
  content9=forbbs(upload.form("content9"))
  content10=forbbs(upload.form("content10"))

if len(content1)>50 or len(content2)>50 or len(content3)>50 or len(content4)>50 or len(content5)>50 or len(content6)>50 or len(content7)>50 or len(content8)>50 or len(content9)>50 or len(content10)>50 then
  Call Error("文件内容最多50字，请返回重试！")
  end if

'if dotype="" then
if up=2 then
Sub Fortxtrel
if bbsid<>"" then
set rs=server.createobject("adodb.recordset")
rs.open "select bbsid,strrel,strall from hmd where bbsid="&bbsid&" and guliid="&myid,conn,1,1
if not rs.eof then
if rs("strrel")>0 then
 Call Error("你在本版已被禁回复！")
  end if
if rs("strall")>0 then
 Call Error("你在本版已被加黑！")
  end if
end if
rs.close
set rs=nothing
end if

set rs=server.createobject("adodb.recordset")
rs.open "select bbsid,strrel,strall from hmd where bbsid=0 and guliid="&myid,conn,1,1
if not rs.eof then
if rs("strrel")>0 then
 Call Error("你已被禁回复！")
  end if
if rs("strall")>0 then
 Call Error("你已被加黑！")
  end if
end if
rs.close
set rs=nothing
end Sub
CALL Fortxtrel
  if content="" then
  Call Error("回复内容不能为空，请返回重试！")
  end if
if len(content)>300 then
  Call Error("回复内容最多300字，请返回重试！")
  end if
else
Sub Fortxtsell
if bbsid<>"" then
set rs=server.createobject("adodb.recordset")
rs.open "select bbsid,strsell,strall from hmd where bbsid="&bbsid&" and guliid="&myid,conn,1,1
if not rs.eof then
if rs("strsell")>0 then
 Call Error("你在本版已被禁言！")
  end if
if rs("strall")>0 then
 Call Error("你在本版已被加黑！")
  end if
end if
rs.close
set rs=nothing
end if

set rs=server.createobject("adodb.recordset")
rs.open "select bbsid,strsell,strall from hmd where bbsid=0 and guliid="&myid,conn,1,1
if not rs.eof then
if rs("strsell")>0 then
 Call Error("你已被禁言！")
  end if
if rs("strall")>0 then
 Call Error("你已被加黑！")
  end if
end if
rs.close
set rs=nothing
end Sub
CALL Fortxtsell

  if title="" or content="" then
  Call Error("标题、内容不能为空，请返回重试！")
  end if
if len(title)<4 then 
  Call Error("标题不能少于4字！")
  end if

if len(title) > 30 then
  Call Error("标题不能多于30字！")
  end if

if len(content)<8 then
  Call Error("内容不能少于8字！")
  end if

  end if
if session("title")=title and session("content")=content then

  Call Error("请不要发重复提交！")
  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)
   
		if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" or fileEXT="exe" or fileEXT="bat" or fileEXT="dll" or fileEXT="php" or fileEXT="jsp" or fileEXT="spx" or fileEXT="cs" then
		 EnableUpload=false
		end if
		if EnableUpload=false then
			msg="这种文件类型不允许上传:asp|asa|aspx|exe|bat|..."
			FoundErr=true
			'showWML()
		  response.end
		end if
		if oFileSize>(MaxFileSize*1024) then
      msg="文件大小超过了限制，最大只能上传" & CStr(MaxFileSize) & "K的文件！"
			FoundErr=true
			'showWML()
	    msg=msg & "<br/><a href=""board.asp?bbsid="&bbsid&"&amp;saytk="&saytk&"&amp;sid="&sid&""">返回论坛</a><br/>"
             response.write msg
             response.write "</p></card></wml>"

		  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(bbsid,username,fid,format,YD_size,files)values"
       intsql= intsql & "(" & bbsid & ",'" & myni& "',"&myid&",'" & fileExt & "','" & sizes & "','" & realpath & "')"
       conn.execute(intsql)
			'连接起来
			kk=kk+1
			if kk=1 then
				if content1<>"" then
				tempcontent=content1&"[br]"
			  end if
			elseif kk=2 then
				if content2<>"" then
				tempcontent=content2&"[br]"
			  end if
			elseif kk=3 then
				if content3<>"" then
				tempcontent=content3&"[br]"
			  end if
			elseif kk=4 then
				if content4<>"" then
				tempcontent=content4&"[br]"
			  end if
			elseif kk=5 then
				if content5<>"" then
				tempcontent=content5&"[br]"
			  end if
			elseif kk=6 then
				if content6<>"" then
				tempcontent=content6&"[br]"
			  end if
			elseif kk=7 then
				if content7<>"" then
				tempcontent=content7&"[br]"
			  end if
			elseif kk=8 then
				if content8<>"" then
				tempcontent=content8&"[br]"
			  end if
			elseif kk=9 then
				if content9<>"" then
				tempcontent=content9&"[br]"
			  end if
			elseif kk=10 then
				if content10<>"" then
				tempcontent=content10&"[br]"
			  end if
			
			end if

			
			if fileExt="gif" or fileExt="jpg" or fileExt="jpeg" or fileExt="png" or fileExt="bmp" then
	
	'Dim Jpeg,Path
	'Set Jpeg = Server.CreateObject("Persits.Jpeg")
	'Path = Server.MapPath(realpath)
	'Jpeg.Open Path
	'Jpeg.Canvas.Font.Color = &HFFFFFF	'颜色
	'Jpeg.Canvas.Font.Family = "宋体"		'字体
	'Jpeg.Canvas.Font.Size = 15		'字体大小
	'Jpeg.Canvas.Font.Bold = true  	'是否为粗体
	'Jpeg.Canvas.Font.ShadowColor = &HFFFFFF		'字影颜色
	'Jpeg.Canvas.Print 5,3,request.ServerVariables("Server_NAME")
	'Jpeg.Canvas.Print 5,3,"wap.nowtx.cn"
	'Jpeg.Save Server.MapPath(realpath)
	'Set Jpeg = Nothing

'--------看空间支持与否------------		
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=70  '定义相册的列表缩略图的大小,以宽为标准
                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=hi/hhi
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 from upfile where id="&upfileid,conn,1,2
if not rs.eof then
         rs("smallfiles")="photo/"&photoname
         rs("filesname")=upfilename
         rs("smallstr")=1
         rs.update
        end if
       rs.close
  set rs=nothing
       
'--------看空间支持与否------------	

		     msg=msg&kk&"."&upfilename&"("&sizes&"K)[br][img]"&realpath&"[/img][br](url="&realpath&")点击下载(/url)(url=diy.asp?bbsid="&bbsid&"&amp;tid=[tid]&amp;path="&replace(realpath,"bbs/","")&"&amp;sid=@@sid@@)缩放(/url)[br]"&tempcontent
			else
		     msg=msg&kk&"."&upfilename&"("&sizes&"K)[br](url=down.asp?bbsid="&bbsid&"&amp;tid=[tid]&amp;path="&enCode_base64(replace(realpath,"bbs/",""))&"&amp;sid=@@sid@@)下载附件(/url)[br]"&tempcontent
		  end if
		  
		  end if
		
		end if
	
		set file=nothing
		
   tempcontent=""
	
next
    
	set upload=nothing

		  if kk>0 then
			content=content&"[br]--------[br]共有"&kk&"个附件:[br]"&msg
		  end if
		  '写入论坛表数据库
if up=2 then
'回复文件
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select * from relist",conn,1,3
rs.addnew
rs("nr")=content
rs("fid")=myid
rs("tid")=tid
rs("fni")=myni
rs("htm")=now()

rs.update
rs.close
set rs=nothing

        session("content")=content
	    msg="您的回复已成功发表！<br/><a href=""topic.asp?bbsid="&bbsid&"&amp;tid="&tid&"&amp;saytk="&saytk&"&amp;sid="&sid&""">返回主帖</a><br/>"

conn.execute("update Users set myjb=myjb+"&clng(wjhjb)&", myjy=myjy+"&clng(wjhjy)&",myrelnum = myrelnum+1 where ID="&myid)

'编辑帖子
elseif up=3 then
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select * from sell Where id="&tid,conn,1,3
rs("txt")=content
rs("name")=title
rs("fid")=myid
rs("fname")=myni
rs("bbsid")=bbsid
rs.update
rs.close
set rs=nothing
        session("title")=title
        session("content")=content

	    msg="您的帖子已成功编辑！<br/><a href=""topic.asp?bbsid="&bbsid&"&amp;tid="&tid&"&amp;saytk="&saytk&"&amp;sid="&sid&""">返回主帖</a><br/>"
else
'正常文件帖
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select * from sell",conn,1,3
rs.addnew
rs("txt")=content
rs("name")=title
rs("fid")=myid
rs("fname")=myni
rs("bbsid")=bbsid
rs.update
rs.close
set rs=nothing  
        session("title")=title
        session("content")=content

	    msg="您的帖子已成功发表！<br/><a href=""board.asp?bbsid="&bbsid&"&amp;saytk="&saytk&"&amp;sid="&sid&""">返回论坛</a><br/>"
conn.execute("update Users set myjb=myjb+"&clng(wjtjb)&", myjy=myjy+"&clng(wjtjy)&",mysellnum = mysellnum+1 where ID="&myid)
end if
		 conn.close
set conn=nothing
			
%>
<%=msg%>
<a href="index.asp?sid=<%=sid%>&saytk=<%=saytk%>">社区首页</a><br/>
</p></card></wml>