设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > ASP

用ASP实现多图片上传到指定的目录并存到数据库

作者:佚名 出处:网络转载 时间:08-29 点击:

内容载入中...
 

关于图片上传的例子在网上有很多文章和原代码。但是每次上论坛浏览帖子的时候都是看到很多网友对图片上传感到头疼和麻烦。其实这个问题也是曾经让我感到头疼。也看过了不少的文章和代码。现在我写的这篇文章是把我比较喜欢的一篇代码和动网里的高手对这篇代码优化后再加上我增加一些代码结合出来的!呵呵,其实这篇文章是沾了写这篇代码的人(稻香居士)和动网里那些高手的光。:)
好了,不说废话了。开始来搭建所需要的环境和数据结构!
先新建一个名字叫photo的文件夹。(我在这里就是把图片上传到这个文件夹里的。)建立一个名字叫database的数据库。再接着建立一个名字叫sFile的表。表里设计四个字段分别是id(int),image(varchar),image1(varchar),image2(varchar)。我这里用的数据库是SQL。
相关的文件

register.asp
<html>
<head>
<title>文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="save.asp">
  <table width="50%" border="1" cellspacing="0" cellpadding="0" align="center">
    <tr>
      <td width="20%"><a href="#"  OnClick="javascript:window.open('/reg_upload.asp',null,'    left=40%,top=40%,height=250,width=470,status=yes,toolbar=no,menubar=no,resizable=yes,copyhistory=yes,scrollbars=yes,location=no,status=no,titlebar=no')">图片上传</a></td>
      <td width="80%">  
        <input type="text" name="myface">
         
        <input type="text" name="myface1">
         
        <input type="text" name="myface2">
        (此处用户不必填图片上传后自动生成) </td>
    </tr>
    <tr>
      <td colspan="2"  align="center">
        <input type="submit" name="Submit" value="提交">
        <input type="reset" name="Submit2" value="重设">
      </td>
    </tr>
  </table>
</form>
</body>
</html>

reg_upload.asp
<html>
<head>
<title></title>
<meta http-equiv="Content-Type"  content="text/html; charset=gb2312">
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body leftmargin="0" topmargin="0"   >
  <br>
<br>
<br>
<table width="90%" border="0" align="center" bgcolor="#000000" height="152" cellspacing="1">
  <tr>
    <td height="34" align="center" bgcolor="#FFFFFF"><font color="#FFFF33"><b><font size="4" color="#000000">选择图片</font></b></font></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">
      <form name="form"  method="post" action="upfile.asp" enctype="multipart/form-data" >
        <input type="hidden" name="filepath" value="photo">
        <input type="hidden"  name="act" value="upload">
        <input type="file" name="file1"  size="30"><br>
         <input type="file" name="file2" size="30"><br>
         <input type="file" name="file3" size="30">
          
        <input  type="submit" name="Submit" value="粘 贴" class="tl">
      </form>
    </td>
  </tr>
</table>
</body>
</html>

upfile.asp
<!--#include FILE="upload.inc"-->
<html>
<head>
<title>文件上传</title>
</head>
<body>
<%
dim arr(3)
dim upload,file,formName,formPath,iCount,filename,fileExt,i
set upload=new upload_5xSoft ''建立上传对象


formPath=upload.form("filepath")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
iCount=0
i=0
for each formName in upload.file ''列出所有上传了的文件
    set file=upload.file(formName)  ''生成一个文件对象
   
    if file.filesize<0 then
        response.write "<font size=2>请先选择你要上传的图片 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
        response.end
document.getElementById('loading').style.display="none";

收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口
>> 下一篇 :web.config

站长学院

推荐信息