<!--#include FILE="../inc/checklogin.asp"-->
<!--#include FILE="../inc/clsUp.asp"-->
<!--#include FILE="../../inc/conn.asp"-->
<!--#include FILE="../../../inc/charfunction.asp"-->
<%
'sub UploadSave()
on error resume next
dim upfile,formPath,ServerPath,FSPath,formName,FileName,oFile,upfilecount,errstr,imagememo
upfilecount=0
set upfile=new clsUp ''建立上传对象
upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;php;jsp"	'设置上传类型的黑名单
upfile.AllowExt="jpg;gif"
upfile.GetData (512000)   '取得上传数据,限制最大上传500k

content=upfile.form("content")
title=chkstr(upfile.form("title"))
newstype=chkstr(upfile.form("newstype"))
TitleFontColor=chkstr(upfile.form("TitleFontColor"))
keyword=chkstr(upfile.form("keyword"))
sendpost=chkstr(upfile.form("sendpost"))
topinfo=chkstr(upfile.form("topinfo"))
OpenComment=chkstr(upfile.form("OpenComment"))

if newstype=1 then
	if upfile.isErr then  '如果出错
		select case upfile.isErr
		case 1
			errstr="1" '你没有上传数据呀???是不是搞错了??
		case 2
			errstr="2" '你上传的文件超出我们的限制,最大500k!
		end select
	else
		FSPath=Server.mappath("../upload")&"/"'取得当前文件在服务器路径
		for each formName in upfile.file '列出所有上传了的文件
		   set oFile=upfile.file(formname)
		   if (lcase(upfile.GetFileExt(oFile.filename)<>"gif")) and (lcase(upfile.GetFileExt(oFile.filename)<>"jpg")) then
			   errstr="3" '错误文件类型，只能上传JPG或GIF图片!
		   else
			   randomize
			   FileName=upfile.GetNewFileName()&"."&upfile.GetFileExt(oFile.filename)
			   upfile.SaveToFile formname,FSPath&FileName 
			   filesize=oFile.Filesize\1024
				if upfile.iserr then 
					errstr=upfile.errmessage
				else
					upfilecount=upfilecount+1
					errstr="4" '成功
					'sql="insert into web_news(newsimage,imagecontent,imagesize,uploaddate,uploadtime,username) values('"&filename&"','"&imagememo&"','"&filesize&"','"&date()&"','"&time()&"','"&session("username")&"')"
					'conn.execute sql
					set rs=server.CreateObject("adodb.recordset")
					sql="select * from web_news"
					rs.open sql,conn,1,3
					rs.addnew()
						rs("newsimage")=filename
						rs("title")=title
						rs("content")=content
						rs("keyword")=keyword
						rs("newstype")=1
						rs("topinfo")=topinfo
						rs("lastper")=session("adminname")
						rs("sendper")=session("adminname")
						rs("TitleFontColor")=TitleFontColor
						rs("OpenComment")=OpenComment
						rs("sendpost")=sendpost
					rs.update()
					rs.close
					set rs=nothing
					call closeconn()
				end if
			end if
			set oFile=nothing
		next
	end if
	set upfile=nothing
	'end sub
	'call UploadSave()
	select case errstr
		case "1"
			errstr="你没有上传数据呀???是不是搞错了??"
		case "2"
			errstr="你上传的文件超出我们的限制,最大500k!"
		case "3"
			errstr="错误文件类型，只能上传JPG或GIF图片!"
		case "4"
			'if action="pic_add" then 
				response.Redirect"index.asp"
		case else
			errstr=errstr
	end select
	call closeconn()
	str="<center>"
	str=str&"<table width='80%' border=0><tr>"
	str=str&"<td align='center' style='font-size:12px;'>"
	str=str&errstr
	str=str&"</td></tr></table></center>"
	response.Write str
else
					set rs=server.CreateObject("adodb.recordset")
					sql="select * from web_news"
					rs.open sql,conn,1,3
					rs.addnew()
						rs("title")=title
						rs("content")=content
						rs("keyword")=keyword
						rs("newstype")=0
						rs("topinfo")=topinfo
						rs("lastper")=session("adminname")
						rs("sendper")=session("adminname")
						rs("TitleFontColor")=TitleFontColor
						rs("OpenComment")=OpenComment
						rs("sendpost")=sendpost
					rs.update()
					rs.close
					set rs=nothing
					call closeconn()
					response.Redirect"index.asp"
end if
%>