<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="upfile_class.asp"-->
<!--#include file="checklogin.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>修改信息</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #FF0000}
.width100{width:100%;}

-->
</style>
<LINK media=screen href="../js/dhtmlgoodies_calendar.css" rel=stylesheet></LINK>
<SCRIPT src="../js/dhtmlgoodies_calendar.js" type=text/javascript></SCRIPT>
</head>

<body>
<!--#include file="top.asp"-->
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top">
	<%
dim act
act=request.querystring("act")
if(act="do") then
	call upload_file()
	response.write("<p align=""center""><a href=""main.asp"">返回</a></p>")
else
	call mod_personalinfo()
end if
%>    </td>
  </tr>
</table>
<%


sub upload_file()
	dim current_time,current_M,current_D,todayStr,current_Floler,imgSavePath,imgSaveFolder,SavePath,arrUpFileType,isEnableUpload
	dim msg,FoundErr,fileSize,PicDesc
	isEnableUpload=false
	FoundErr=false
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	current_time=now()
	current_M=chan_data(current_time)
	current_D=chan_day(current_time)
	todayStr=current_M&current_D
	current_Folder=server.mappath("../"&UpfilePath)&"\"&todayStr	
	'创建文件夹
	If (fs.FolderExists(current_Folder)) Then

	Else
		fs.CreateFolder(current_Folder)
	End If
	set fs=nothing
	imgSaveFolder=UpfilePath&"/"&todayStr
	
	set upload=new upfile_class ''建立上传对象
	upload.GetData(10240000)   '取得上传数据,限制最大上传100M
	if upload.err > 0 then  '如果出错
		select case upload.err
			case 1
				response.write "请先选择你要上传的文件！"
			case 2
				response.write "你上传的文件总大小超出了最大限制（100M）"
		end select
		response.end
	end if	
	if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
	
	PicDesc=upload.Form("PicDesc")
	response.Write(PicDesc)
	for each formName in upload.file '列出所有上传了的文件
		set ofile=upload.file(formName)  '生成一个文件对象
		If instr(oFile.FileType,"text")<>0 then
			response.write   "<script>alert('error！');</script>"   
			Response.End   
	  	end   if
		oFileSize=ofile.filesize
		if oFileSize>(MaxUpFileSize) then
 			msg="文件大小超过了限制，最大只能上传" & CStr(MaxUpFileSize) & "的文件！"
			FoundErr=true
		end if
		if oFileSize>0 then
			fileExts=lcase(trim(ofile.fileExt))		
			arrUpFileType=split(UpFileType,"|")
			for i=0 to ubound(arrUpFileType)
				if fileExts=trim(arrUpFileType(i)) then
					isEnableUpload=true
					fileExts=arrUpFileType(i)
					exit for
				end if
			next
			if isEnableUpload=false then
				msg="这种文件类型不允许上传！\n\n只允许上传这几种文件类型：" & UpFileType
				FoundErr=true
			end if	
			
			if FoundErr<>true then
				randomize
				ranNum=int(900*rnd)+100
				filename=chan_file(current_time)&ranNum&"."&fileExts		
				ofile.SaveToFile current_Folder&"\"&FileName   '保存文件
				fileSize=cstr(round(oFileSize/1024)) & "K"
				'保存至库
				set rs=server.CreateObject("adodb.recordset")
				rs.open "select * from t_member where UserId='"&checkusername&"'",conn,3,3
				rs("Photo")=imgSaveFolder&"/"&filename
				rs.update
				rs.close
				set rs=nothing
				response.Write("<script language=""javascript"">"&Chr(10))
				'response.Write("window.parent.IframeID.document.body.innerHTML+=""<img src="&imgSaveFolder&"/"&filename&">"";"&Chr(10))
				response.Write("document.write('<div style=""background-color:#ffffff; padding-top:5px; height:30px; padding-left:10px;"" align=""left"">成功上传照片！</div>');")
				response.Write("</script>"&Chr(10))
			else
				response.Write("<script language=""javascript"">"&Chr(10))
				response.Write("alert(""")
				response.Write(msg)
				response.Write(""");")
				response.Write("history.back();"&Chr(10)&"</script>")			
			end if		
			set ofile=nothing
		end if
		exit for
	next
	set upload=nothing	
end sub
sub mod_personalinfo
%>
<form action="?act=do" method="post" enctype="multipart/form-data" name="PostForm" id="PostForm">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" class="border">
  <tr>
    <td height="28" colspan="2" class="th_title">上传照片</td>
  </tr>
  <tr>
    <td width="18%" class="td_row">上传：</td>
    <td width="82%" class="td_row"><input name="FileName" type="file" id="FileName" size="30" maxlength="100" /></td>
  </tr>
  <tr>
    <td class="td_row">&nbsp;</td>
    <td class="td_row"><input type="submit" name="Submit" value="确 定" />
      <input type="reset" name="Submit2" value="取 消" /></td>
  </tr>
</table>
</form>
<%
end sub
%>
</body>
</html>
<%
call connclose()
%>