ASP 多图片上传

1:上传页面

 

 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!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">
* { margin:0;padding:0;}
#file_group { list-style:none;}
#file_group li { background: url(icon_file.gif) no-repeat left; padding-left:25px; height:24px;}
#file_group input{ height:24px;line-height:22px;font-family:Verdana;}
#file_group button{ height:24px;}
#add{width:39px}
a:link {
 color: #000000;
 text-decoration: none;
}
a:visited {
 color: #000000;
 text-decoration: none;
}
a:hover {
 color: #FF0000;
 text-decoration: none;
}
a:active {
 text-decoration: none;
}
</style>
<script type="text/javascript">
var file_num=1;
function addFile() {
 if(file_num>=10) return alert("一次只允许上传10个文件!");
 var temp;
 temp="<li><input type=/"file/" name=/"mfile" + (file_num+1) + "/" size=/"70/" />&nbsp;<button οnclick=/"removeSelf(this)/">删除</button></li>";
 var obj=document.getElementById("file_group");
 obj.innerHTML=obj.innerHTML+temp;
 file_num++;
}
function removeSelf(node) {
 var obj=node.parentNode.parentNode.removeChild(node.parentNode);
 file_num--;
}
function chkUpload(){
 var obj=document.getElementsByTagName("input");
 for (i=0;i<obj.length;i++)
 {
  if(obj[i].type=="file")
  {
   if(obj[i].value!="")
   {
    var getStr=obj[i].value.match(//.(jpg|gif|png|bmp)$/);
    if(!getStr)
    {
     alert("只允许上传 jpg、gif、png、bmp 格式的图片!");
     return false;
    }
   }
  }
 }//end for
 return true;
}
function mysubmit(){
 var ret=false;
 if(chkUpload()){ ret=true;}
 return ret;
}
</script>
</head>

<body bgcolor="#9aaed0">
<!--#include file="conn.asp"-->
<%
  dim idnum
  idnum=Cint(request("idnum"))
%>
<form method="post" action="upload.asp?idnum=<%=idnum%>" name="uploadform" enctype="multipart/form-data" οnsubmit="return mysubmit();">
<p>图片上传:<a href=<%if session("username")<>"" then%>"pic_background.asp?idnum=<%=idnum%>"<%end if%><%if session("puser")<>"" then%>"user_bg.asp?idnum=<%=idnum%>"<%end if%>>返回</a></p><br />
<ul id="file_group">
 <li><input name="mfile1" type="file" value="" size="70" />
 <input id="add" type="button" οnclick="addFile()" value="添加" />
 </li>
</ul>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(只能上传jpg|gif|png|bmp文件)<hr />
<pre>                                                    <input name="submit" type="submit" value="上传" /></pre>
</form>

</body>
</html

 

 

 

2:处理页面

 

 

<!--#include file="conn.asp"-->
<%Server.ScriptTimeOut=5000%>
<!--#include file="upload_5xsoft.inc"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文件上传</title>
<style type="text/css">
<!--
a:link {
 text-decoration: none;
 color: #000000;
}
a:visited {
 text-decoration: none;
 color: #000000;
}
a:hover {
 text-decoration: none;
 color: #FF0000;
}
a:active {
 text-decoration: none;
}
-->
</style>
</head>
<body bgcolor="#9aaed0">
<br>图片文件上传!<hr size=1 noshadow width=300 align=left><br>
<%
Response.Charset="gb2312"

dim upload,file,formName,uploadPath,iCount,idnum,fname,t,i,uSQL,ra,rt,ran,rs,rs1,selsql,sqla,tSQL,str
set upload=new upload_5xsoft
idnum=Cint(request.QueryString("idnum"))

  selsql="select title,piclist,album from albumpic where id="&idnum
  set rs=cn.execute(selsql)
  if not rs.eof then
    ran=rs("album")
    sqla="select albumname from album where album="&ran
    set rs1=cn.execute(sqla)
    if not rs1.eof then
      ra=rs1("albumname")
    end if
    rt=rs("title")
    str=rs("piclist")
  end if
  uploadPath="../images/"&ra&"/"&rt&"/"

iCount=0

for each formName in upload.objFile
  set file=upload.file(formName)
  if file.FileSize>0 then
    fname=upload.MakeFileName(file.FileExt) 
    file.SaveAs Server.mappath(uploadPath & fname)
 str=str&fname&"|"
     uSQL="update albumpic set piclist='"&str&"'where id="&idnum                 '更新数据库piclist字段的内容
    cn.execute(uSQL) 
    response.write file.FilePath & file.FileName &" (" & file.FileSize & ")=> " & fname & " 上传成功!<br>"  
    iCount=iCount+1   
  end if   
next
    
cn.close
set Extsql=nothing
set rs=nothing
set rs1=nothing
set cn=nothing
response.write "<br />"&iCount & "个文件上传成功![<a href='uploadpic.asp?idnum="&idnum&"'>返回</a>]"
%>
</body>
</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值