<%
'LyfUpload 
'=========================================================
' Copyright (C) 2003-2006 www.jspxNet.com All rights reserved.
' Email: nbcjh@163.com QQ:10092437
' WebSite: http://www.jspxnet.com

'=========================================================
Dim mUploadPath,mReturnForm,mReturnText
mUploadPath = Request.QueryString("UploadPath")
mReturnForm = Request.QueryString("ReturnForm")
mReturnText = Request.QueryString("ReturnText")

''将当前的日期和时间转为文件名
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 
'GetExtendName
Function GetExtendName(FileName)
  dim ExtName
  ExtName = LCase(FileName)
  ExtName = right(ExtName,3)
  ExtName = right(ExtName,3-Instr(ExtName,"."))
  GetExtendName = ExtName
End Function
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../include/Style.css" rel="stylesheet" type="text/css">
<Script language="javascript">
function mysubmit(theform)
{
    if(theform.file1.value=="")
    {
    alert("请点击浏览按钮，选择您要上传的jpg或gif文件!")
    theform.file1.focus;
    return (false);
    }
    else
    {
    str= theform.file1.value;
    strs=str.toLowerCase();
    lens=strs.length;
    extname=strs.substring(lens-4,lens);
    if(extname!=".jpg" && extname!=".gif")
    {
    alert("请选择jpg或gif文件!");
    return (false);
    }
    }
    return (true);
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0">
<table width="422" border="0" cellspacing="0" cellpadding="0" height="138">
  <tr>
  <form name="form1" method="post" action="UploadWindows.jsp?action=upload&UploadPath=<%=mUploadPath%>&ReturnForm=<%=mReturnForm%>&ReturnText=<%=mReturnText%>&fname=<%=session("fname")%>" onsubmit="return mysubmit(this)" enctype="multipart/form-data" >
      <td width="439" valign="middle"> 
        <table width="98%" border="1" cellspacing="0" cellpadding="5" bordercolordark="#CCCCCC" bordercolorlight="#000000" height="43" align="center">
          <tr bgcolor="#CCCCCC"> 
            <td height="22" align="left" valign="middle" bgcolor="#f2f2f2"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr> 
                  <td width="84%"><b>文件上传：</b>
<%
if Request.Querystring("action")="upload" then
mUploadPath = Request.QueryString("UploadPath")
mReturnForm = Request.QueryString("ReturnForm")
mReturnText = Request.QueryString("ReturnText")
	if request.QueryString("fname")<>"" then
      delfname=server.mappath(mUploadPath)+"\"+Request.QueryString("fname")
      set TestFileObject=Server.Createobject("Scripting.FileSystemObject")
      if  TestFileObject.FileExists(delfname) then
         set NewFile=TestFileObject.getfile(delfname)
        Newfile.delete
      end if
	 end if
'-----------------------------------
filename="file1"
Set obj = Server.CreateObject("LyfUpload.UploadFile")
obj.maxsize = 205138  '设置文件上传的最大为2048个字节(200K)
obj.extname = "gif,jpg"
if Trim(cstr(obj.filetype("file1")))="image/pjpeg" then mExName="jpg"
if Trim(cstr(obj.filetype("file1")))="image/gif" then mExName="gif"
fname = makefilename(now()) & "." & mExName
upfname=server.mappath(mUploadPath)
ss=obj.SaveFile(filename, upfname, false,fname) '保存文件到服务器
If obj.filesize = 0 then
   Response.write "<font color=red><b>上传失败，原因是文件大小不能超过200K！</b></font>"
   Response.write"[<a href='javascript:window.close()'>关闭窗口</a>] "
   Response.end
End if

set obj = nothing
  Response.write "&nbsp;&nbsp;&nbsp;&nbsp;<font color=red><b>恭喜您！文件上传成功！</b></font>"
  Response.write "<script language='JavaScript'>opener.document."&mReturnForm + "." + mReturnText&".value='"&fname&"'</script>"
  Response.write "<script>window.close();</script>"
end if
%>

                  </td>
                  <td width="16%" align="right">[<a href="javascript:window.close()">关闭窗口</a>] 
                  </td>
                </tr>
              </table></td>
          </tr>
          <tr align="left" valign="middle" bgcolor="#eeeeee"> 
            <td bgcolor="#fcfcfc" height="16"> 注：只能上传.gif或.jpg类型的图片，且图片的容量必须在200k之内！</td>
          </tr>
          <tr align="center" valign="middle"> 
            <td align="left" id="upid"> 
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr> 
                  <td height="7" align="center">文件名： 
                    <input type="file" name="file1"  value=""  style="width:310;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff"> 
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr align="center" valign="middle" bgcolor="#eeeeee"> 
            <td bgcolor="#fcfcfc" height="2"> 
              <input type="submit" name="Submit" value="· 提交 ·" style="width:80;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff">
              <input type="reset" name="Submit2" value="· 重执 ·" style="width:80;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff">
            </td>
          </tr>
        </table>
      </td>
    </form>
    </tr>
  </table>
</body>
</html>
