
<!--#include file="../conn.asp"-->
<!--#include file="../check.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="upsave.inc"-->
<body leftmargin="0" topmargin="0" bgcolor=#F3F3FA>
<style type="text/css">*{font-size:12px;}</style>
<%
response.Charset="GBK"
Server.ScriptTimeOut=999999
dim formName,formPath,filename,file_name,fileExt,Filesize,F_Type,formPath1

call upload()

'===========================无组件上传============================
sub upload()
dim upload,file,ranNum,rename,filename1
set upload=new UpFile_Class ''建立上传对象
upload.GetDate (1000*1024)   '取得上传数据,不限大小


if upload.err > 0 then
    select case upload.err
	case 1
	Response.Write "<table><tr><td bgcolor=#F3F3FA>请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>"
	case 2
	Response.Write "<table><tr><td bgcolor=#F3F3FA>文件大小超过了限制　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>"
	end select
	exit sub
	else
	formPath="../../uploadimg/" & getSavePicPath() & "/"
	formPath = replace(formPath,"//","/")
	formPath = replace(formPath,chr(10),"")
	formPath = replace(formPath,chr(13),"")
	
	formPath1 = replace(formPath,"../../","")
	'upload.form("filepath")
	'在目录后加(/)
	'if right(formPath,1)<>"/" then formPath=formPath&"/"

for each formName in upload.file ''列出所有上传了的文件
	set file=upload.file(formName)  ''生成一个文件对象

	fileExt=lcase(file.FileExt)
	
	'判断文件类型
	if lcase(fileEXT)="asp" and lcase(fileEXT)="asa" and lcase(fileEXT)="aspx" then
		CheckFileExt(fileEXT)=false
	end if
	if CheckFileExt(fileEXT)=false then
 	response.write "<table><tr><td bgcolor=#F3F3FA>文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>"
	response.end
	end if
	
	'付值变量
	randomize
	ranNum=int(90000*rnd)+10000
	file_name=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
	filename=file_name&"."&fileExt
	rename=filename&"|"
	
	filename1=formPath&filename

	Filesize=file.FileSize
	
	if not FSOOBJ.IsFolder(formPath) then
		response.write formPath
		FSOOBJ.CreateFolder formPath
	end if
	
	'记录文件
	if Filesize>0 then         '如果 FileSize > 0 说明有文件数据
	file.SaveToFile Server.mappath(FileName1)   ''执行上传文件
'call ImgWriter(FileName1)'添加水印
	call checksave()			'记录文件
	end if
	set file=nothing
next
end if
set upload=nothing
	response.write "<table><tr><td bgcolor=#F3F3FA>"  & formPath1 & FileName &"上传成功![ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>"
end sub

'判断文件类型是否合格
Private Function CheckFileExt (fileEXT)
dim Forumupload,i
Forumupload=split("jpg|gif|png","|")
	for i=0 to ubound(Forumupload)
		if lcase(fileEXT)=lcase(trim(Forumupload(i))) then
			CheckFileExt=true
			exit Function
		else
			CheckFileExt=false
		end if
	next
End Function

Private sub checksave()
	'插入上传表并获得ID
	response.write "<script>parent.form2.pic.value='"&formPath1&FileName&"'</script>"
end Sub

Sub ImgWriter(SaveImgPath)    '添加水印
dim jpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open Server.MapPath(SaveImgPath)
Jpeg.Canvas.Font.Color = &Hffffff
Jpeg.Canvas.Font.Family = "Tahoma"
Jpeg.Canvas.Font.Size = 16
Jpeg.Canvas.Font.ShadowColor = &H000000
Jpeg.Canvas.Font.ShadowXoffset = -1
Jpeg.Canvas.Font.ShadowYoffset = 1
Jpeg.Canvas.Font.Bold = true
Jpeg.Canvas.Print 10, 10, "Maxz.cn"
Jpeg.Canvas.Pen.Color = &Heeeeee
Jpeg.Canvas.Pen.Width = 1
Jpeg.Canvas.Brush.Solid = False
Jpeg.Canvas.Bar 0, 0, Jpeg.Width, Jpeg.Height
Jpeg.Save Server.MapPath(SaveImgPath)
End Sub
%>
