<!--#include file="conn.asp"-->
<!--#include file="upfile_class.asp"-->
<!-- #include file="touxianfun.asp" -->
<!-- #include file="ispicfun.asp" -->
<%
Server.ScriptTimeout = 5000
call FTBBS_HTML_MB
url=Application("FTBBSMB")(10,0)
upfiletype=Application("FTBBSMB")(12,0)
upfilesize=Application("FTBBSMB")(13,0)
if right(url,1)<>"/" then url=url&"/"
htmfilename=trim(Request.QueryString("htmfilename"))
%>
<html><title>保存上传(飞天论坛)</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=javascript src="inc/cookies.js"></script>
<script>
var stylecook = getCookie("STYLESHOW");
var style;
var strstyle;
if(stylecook=="")
{
 stylecook=1;
}
else
{
 stylecook++;
}
style="ftbbs0"+stylecook+".css";
strstyle="<link href=\"css/"+style+"\"  rel=\"stylesheet\" type=\"text/css\"> ";
document.write(strstyle);
</script>
<body topmargin="0" class=td005>
<div class=new12>
<%
if userlogin="N" then
   Response.Write "<font color=red>你还没有登录</font>"
   Response.end()
end if
if Application("FTBBSMB")(7,0)="M" then
 inFolder=year(date())&month(date())
else
 inFolder=year(date())&month(date())&day(date())
end if
 myFolder = inFolder
 myFolder = Server.MapPath(myFolder)

Set fileStreamObj = CreateObject("Scripting.FileSystemObject")
If fileStreamObj.FolderExists(myFolder) = False Then
   fileStreamObj.CreateFolder (myFolder)
End If

dim upload,file,upfile,formPath,ServerPath,FSPath,formName,companyName,oFile,upfilecount,SaveFileName,SavePathFileName
set upload=new Ftbbs_Class
upload.AllowExt=upfiletype    '设置上传文件类型
upload.GetData (upfilesize)   '取得上传文件大小

formPath=inFolder
FilePath=inFolder&"/"
if right(formPath,1)<>"/" then formPath=formPath&"/"
if upload.isErr then
    select case upload.isErr
    case 1
        Response.Write "<font color=red>上传文件不能为空</font>"
        Response.Write "&nbsp;&nbsp;<a href=ReFtbbsUpFile.asp?filename="&htmfilename&">重新上传</a>"
    case 2
        Response.Write "系统限制上传文件大小在<font color=red>"&upfilesize&"</font>字节以下&nbsp;&nbsp;<a href=ReFtbbsUpFile.asp?filename="&htmfilename&">重新上传</a>"
    end select
else
    for each formName in upload.file '列出所有上传了的文件
	   set oFile=upload.file(formname)
	   filesize=oFile.FileSize '取得文件大小
	   
	   vfname = makefilename(now())
	   Randomize
	   Random=Int((1000 - 100 + 1) * Rnd + 100)
	   vfname=vfname&"_"&Random
	   FileExt=oFile.FileExt '取文件扩展名 
	   filetype=oFile.FileMIME '取文件头类型
	   if filetype="text/plain" then
	      response.write "您上传的文件有问题!&nbsp;&nbsp;<a href=FtbbsUpFile.asp?filename=" & htmfilename & ">重新上传</a>"
		  response.end
	   end if
	   fname = formPath&vfname & "." & FileExt
	   todbpath=vfname & "." & FileExt

       SavePathFileName = Server.MapPath(fname)
       upload.SaveToFile formName,SavePathFileName '保存文件
       if upload.iserr then 
         Response.Write upload.errmessage
       else
         if Application("FTBBSMB")(15,0)=1 and FileExt="jpg" then
		    if Application("FTBBSMB")(36,0)=1 then
		    imgtologo fname
			else
			imgtourl url,fname
			end if
		 end if
		 Call ispic(SavePathFileName)
         Response.Write "上传成功"
         Response.Write "&nbsp;&nbsp;<a href=ReFtbbsUpFile.asp?filename="&htmfilename&">继续上传</a>"

         sql="insert into ftbbs_upload (upload_pic,file_type,upload_size,upload_ext,userid,upload_htm,clubuser_id) values('"&inFolder&"/"&todbpath&"',0,'"&filesize&"','"&FileExt&"','"&request.cookies("name")&"','"&htmfilename&"',"&request.cookies("clubuser_id")&")"
         conn.Execute(sql)
         sql="select top 1 id from ftbbs_upload where upload_pic='"&inFolder&"/"&todbpath&"' order by id desc"
         set rs=conn.execute(sql)
         id=rs("id")
         closedb
         Call ReturnPostFile(FileExt,url,FilePath,todbpath)
       end if
       set oFile = nothing
    next
end if    
set upload=nothing
Function ReturnPostFile(Ext,url,FilePath,FileName)
If ext="jpg" or ext="gif" or ext="bmp" or ext="png" or ext="jpeg" then
   session("bbs_img_display")=1
   session("bbs_img")=Ext
%>
<script>
{
img="<img src=<%=FilePath%><%=FileName%> border=0 resize='1'>"
}
document.ftbbsmenu = new Function('return false')
parent.IframeID.document.body.innerHTML+='\n'+img+''
</script>
<%
Else If ext="swf" then
   session("bbs_img_display")=2
   session("bbs_img")=Ext
%>
<script>
{
img="[flash=400,300]<%=url%><%=FilePath%><%=FileName%>[/flash]"
}
document.ftbbsmenu = new Function('return false')
parent.IframeID.document.body.innerHTML+='\n'+img+''
</script>        
<%
else
   session("bbs_img_display")=3
   session("bbs_img")=Ext
%>
<script>
{
//img="[url]<%=url%><%=FilePath%><%=FileName%>[/url]"
img="附件下载请点击:[url]<%=url%>down.asp?id=<%=id%>[/url]"
}
document.ftbbsmenu = new Function('return false')
parent.IframeID.document.body.innerHTML+='\n'+img+''
</script>        
<%
   end if
  end if
End Function
%>
</div>
</body> 
</html>