用ASP实现多图片上传到指定目录并存储数据库
2007-12-19 00:35:51 来源:WEB开发网核心提示: </tr> <tr> <td bgcolor="#FFFFFF"> <form name="form"method="post" action="upfile.asp" enctype=&qu
</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
end if
if file.filesize>100000 then
response.write "<font size=2>图片大小超过了限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
response.end
end if
if fileEXT<>".gif" and fileEXT<>".jpg" then
response.write "<font size=2>文件格式不对 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
response.end
end if
fileExt=lcase(right(file.filename,4))
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName
arr(i)=filename
i=i+1
if file.FileSize>0 then ’如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(filename) ’保存文件
更多精彩
赞助商链接