<!--#include file="../Include/Char.jsp" -->
<!--#include file="../Include/Conn.jsp" -->
<!--#include file="../Include/upload_5xsoft.inc" -->

<%
   function makefilename(fname)
  fname = now()
  fname = replace(fname,"-","")
  fname = replace(fname," ","") 
  fname = replace(fname,":","")
  fname = replace(fname,"PM","")
  fname = replace(fname,"AM","")
  fname = replace(fname,"上午","")
  fname = replace(fname,"下午","")
  makefilename=fname
end function 

function GetExtendName(FileName)
dim ExtName
ExtName = LCase(FileName)
ExtName = right(ExtName,3)
ExtName = right(ExtName,3-Instr(ExtName,"."))
GetExtendName = ExtName
end function
 

 m_ID = request.cookies("UserID")
if Request.ServerVariables("REQUEST_METHOD") = "POST" then 

 dim upload,file,formName,formPath,iCount
 set upload=new upload_5xSoft ''建立上传对象

  m_Title = CheckStr(Upload.form("Title"))
  if m_Title = "" then
     call msgbox("对不起,文字说明不能为空",1)
	 Response.end()
  end if
  
 formPath="UploadImages"
 if right(formPath,1)<>"/" then formPath=formPath&"/" 
  iCount=0

for each formName in upload.file ''列出所有上传了的文件
 set file=upload.file(formName)  ''生成一个文件对象
 
 if file.FileSize <= 0 then    ''如果 FileSize > 0 说明有文件数据
   call MsgBox("对不起，请选择上传图片",1)
   response.end
 else
   
   last=lcase(right(file.filename,4))
   if last <>".gif" and last <>".jpg" then
      call MsgBox("对不起，图片类型出错，请问重新上传",1)
	  response.end
   end if

   FileName1=file.FileName
   vfname = makefilename(now())
   fname = vfname & "." & GetExtendName(file.FileName)
   filename=fname  
	 
  file.SaveAs Server.mappath(formPath&fname)   ''保存文件

        'response.Cookies("UploadImage")=filename
		'REsponse.write m_UserName
		'response.end
    SQL="INSERT INTO citycard_Image(F_Title,F_Image,F_UserName,F_Date,F_Time) VALUES('"&m_Title&"','"&filename&"','"&m_ID&"','"&date&"','"&time&"')"
    Conn.Execute SQL  

		
 iCount=iCount+1
 set file=nothing
 end if
Next


      set upload=nothing  ''删除此对象
      Htmend iCount&" 个文件上传结束!"
 end if

  
sub HtmEnd(Msg)
 set upload=nothing
end sub	 
 
 %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
<link href="../Include/Style.css" rel="stylesheet" type="text/css">

<SCRIPT language=JavaScript src="../include/Popcalendar.js"></SCRIPT>
</head>

<body >
<table width="453" height="115" border="0" cellpadding="4" cellspacing="0" bgcolor="#FFFFFF">
  <form name="form1" enctype="multipart/form-data" method="post" action="">
    <tr> 
      <td width="320" height="44">请选择<font color="#FF0000">jpg,gif</font>图像<br>
        文字说明：<br>
        <input name="Title" type="text" id="Title"></td>
      <td width="114" rowspan="3" align="center">
	  <%
	  If filename<>"" then
	    Response.write  "<img src='UploadImages/"&filename&"' width='110' height='106'>"
	  else
	    Response.write "未上传"
	  End if
	  %>
	  </td>
    </tr>
    <tr> 
      <td> <input type="file" name="file"> <input type="submit" name="Submit" value="上　传"> 
      </td>
    </tr>
    <tr>
      <td align="right" valign="bottom"><input type="button" name="Submit2" onclick="window.close()" value="关　闭"></td>
    </tr>
  </form>
</table>
</body>
</html>
