打印

[asp] 求助 无组件上传多文件取文件名字的问题~

把一个FORM表的 2张图片保存到 数据库的一个表中~
分别的img1和img2~
现在用 无惧无组建上传不知道这个img怎么取值 希望那个大大能具体解释下~代码如下
<!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>
<style type="text/css">
<!--
.tr {font-size: 12pt;}
-->
</style>
</head>

<body>
<form action="up.asp" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="400" border="0" align="center" cellpadding="0" cellspacing="0" class="tr">
    <tr>
      <td width="129" height="30" align="right" class="table">用户名:</td>
      <td width="271" height="30" align="left" class="table"><input name="username" type="text" id="username"  /></td>
    </tr>
    <tr>
      <td height="30" align="right" class="table">密码:</td>
      <td height="30" align="left" class="table"><input name="pwd" type="password" /></td>
    </tr>
    <tr>
      <td height="30" align="right" class="table">头像:</td>
      <td height="30" align="left" class="table"><input name="img" type="file" id="img" /></td>
    </tr>
    <tr>
      <td height="30" align="right" class="table">头像:</td>
      <td height="30" align="left" class="table"><input name="img1" type="file" id="img1" /></td>
    </tr>
    <tr>
      <td height="30" align="right"><input name="Submit" type="submit" value="提交" /></td>
      <td height="30" align="left"><input name="Submit2" type="reset" value="重置" /></td>
    </tr>       
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;  </p>
</form>
</body>
</html>
---------------------------执行页面------------------------------
<!--#include FILE="upfile_class.asp"-->
<%
       Dim upfile,formName,FileName,oFile
       
       Set upfile=new upfile_class ''建立上传对象
       'upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;"       '设置上传类型的黑名单
       upfile.AllowExt = "jpg;gif;bmp;png"       '设置上传类型的白名单
       upfile.GetData (10240000)   '取得上传数据,限制最大上传10M

       Sub CheckSize(Tmp,Str)
              If Tmp.FileSize < 10 Then
                     Response.Write("<script language='javascript'>alert('"&Str&"没有上传图片!');history.go(-1);</script>")
                     Response.End()
              End If       
       End Sub
       
       Sub CheckExt(Tmp,Str)
              'For I = 0 To Ubound(Arr)
                     If Instr(upfile.AllowExt,Tmp.FileExt) <= 0 Then
                            Response.Write("<script language='javascript'>alert('"&Str&"上传的图片格式不正确!');history.go(-1);</script>")
                            Response.End()
                     End If
              'Next
       End Sub
       
       If upfile.isErr Then  '如果出错
              select case upfile.isErr
              case 1
                Response.Write("<script language='javascript'>alert('你没有上传数据呀???是不是搞错了??');history.go(-1);</script>")
              case 2
                Response.Write("<script language='javascript'>alert('你上传的文件超出我们的限制,最大10M');history.go(-1);</script>")
              case 3
                     Response.Write("<script language='javascript'>alert(该后缀文件名不允许上传!只能上传以下格式文件:\n"&upfile.AllowExt&"');history.go(-1);</script>")         
              end select
       Else
              username = upfile.form("username")
              pwd = upfile.form("pwd")
              
              If username = "" Then              '判断用户名是否为空
                     Response.Write("<script language='javascript'>alert('用户名不能为空');history.go(-1);</script>")
                     Response.End()
              End If
              
              Response.Write("用户名:"&username&"<br>密 码:"&pwd&"<br>"&"<br>")
       
              Call CheckSize(upfile.file("img"),"头像一")
              Call CheckExt(upfile.file("img"),"头像一")
              Call CheckSize(upfile.file("img1"),"头像二")
              Call CheckExt(upfile.file("img1"),"头像二")
              
       
              'Response.Write("<br>"&upfile.file("img").FileSize&"<br>"&upfile.file("img1").FileSize)
              
              For Each formname In upfile.file
                     Set oFile = upfile.file(formname)
                     fileName=upfile.AutoSave(formname,server.MapPath("upload")&("\"))   '保存文件,按照当前时间命名,              保存相对路径时需要单独加"/"或"\"              
                     If upfile.isErr Then
                            Response.Write("<script language='javascript'>alert('"&upfile.errmessage&"');history.go(-1);</script>")
                            Response.End()
                     End If              
       
                     Response.Write("上传前的路径:"&oFile.FilePath&"<br>大小:"&oFile.FileSize&"<br>文件名:"&oFile.FileName&"<br>")
                     Response.Write("上传后的路径:"&server.MapPath("upload")&"\"&"<br>文件名:"&fileName&"<p>")
                     
                     Set oFile = Nothing              
              Next
         Set upfile = Nothing
       End If       
%>
-------------
怎么能分别取到img 和 img1的值呢?
file.FileExt 扩展名
file.FileSize 图片大小(B)
名称一般重命名,而且以日期命名,这样容易管理

给你个函数
复制内容到剪贴板
代码:
Public Function GetNewFileName()
dim ranNum:ranNum = int(900*rnd)+100
dim dtNow:dtNow = Now()
randomize
GetNewFileName=year(dtNow) & right("0" & month(dtNow),2) & right("0" & day(dtNow),2) & right("0" & hour(dtNow),2) & right("0" & minute(dtNow),2) & right("0" & second(dtNow),2) & ranNum
End Function
承接ASP定制,http://08-if.cn/
别用无惧类了,无惧类上传的文件太大时,cpu会 占用100%

很多黑客用这个缺陷用来攻击服务器!

真的啊!
我要电影51movs.com
谢谢 回复的2个大大~

TOP

还在为头像烦恼?还在为不能关注好友动态烦忧?快来蓝色理想家园吧!