求助各位大虾!!——应用aspupload,如何编写代码??

sharfly 2005-09-07 10:51:34
我现在急需实现图片上传功能,不要求判断是否有上传图片(已知必须上传),不要求显示进度条;只需能从本机上传图片,把上传到的路径和图片名存入数据库,然后在一个显示页面显示出上传的图片就行了。
我下载了aspupload组件,在网上参考了不少应用aspupload上传图片编写的源码,但都没有成功实现。在此请教各位大虾,哪位能分享一下这方面的成功经验(请确认代码成功通过测试)。谢谢!
...全文
231 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ziseshuijing 2006-04-12
  • 打赏
  • 举报
回复
各位仁兄:
我还不知道怎么用,能不能做一个简单的,把整个代码考上来给小妹我看看啊,
先谢谢了···
sharfly 2005-09-12
  • 打赏
  • 举报
回复
李别的方法简明有效,帮助我解决了难题。谢谢!
kongyeeku 2005-09-12
  • 打赏
  • 举报
回复
Set Upload = Server.CreateObject("Persits.Upload.1")
filename = Server.MapPath("..\upload")
Upload.Save filename
%>
<%
'遍历每个上传图片
i = 1
For Each File in Upload.Files
filepath = File.Path
pos = InStrRev(filepath, "\")
length = len(filepath)
filename = right(filepath,length-pos)
call dbopen()
sql="update 表名 set file"&i&"_name = '"&filename&"'"
conn.execute(sql)
i = i + 1
Next
%>
pzhuyy 2005-09-09
  • 打赏
  • 举报
回复
上传成功后,会显示当前文件的路径,你把它写入数据库中就可以了!
pzhuyy 2005-09-09
  • 打赏
  • 举报
回复
aspUpload直接就可以上传了呀!他是上传到文件夹,然后取出路径和文件名存入数据库即可!
aspupload文件:
fileconfig.asp
'上传配置文件
<%
Dim UploadFilePath,UploadLimitSize,NotAllowfileext,BrowerFilePath
UploadFilePath =year(now)&"_"&month(now)&"_"&day(now)&"/"
'文件上传路径

BrowerFilePath = "/"

UploadLimitSize = 1024*50 '50M
'最大上传文件大小,单位为K

Allowfileext = "png|jpg|gif"
'可以上传的文件类型

function CanUpload(Fileurl)
Fileurl = lcase("|"& Mid(Fileurl, InstrRev(Fileurl, ".") + 1)& "|")
NotAllowfileextstr = "|"&Allowfileext&"|"
if instr(NotAllowfileextstr,Fileurl)>0 then
CanUpload = true
else
CanUpload = false
end if
end function

Function CreateFolder(Filepath)
Dim fso, f
on error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(Filepath) then
Set f = fso.CreateFolder(Filepath)
set f = Nothing
end if
set fso = Nothing
End Function
%>

uploadfile.asp
'上传页面
<!--#include file='fileconfig.asp'-->
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
<style>
<!--
* {font:12px;}
-->
</style>
</head>
<body>
<%
On Error Resume Next
Server.ScriptTimeOut=999999
if request("act")="upload" then
dim folder,savepath
savepath=Server.MapPath(UploadFilePath)
CreateFolder(savepath)
Set Upload=Server.CreateObject("Persits.Upload")
Upload.SetMaxSize UploadLimitSize*1024, True
Upload.OverwriteFiles = false
if Request.QueryString("PID") = "" then
Upload.ProgressID="010D60EB00C5AA4B"
else
Upload.ProgressID=Request.QueryString("PID")
end if
Count=Upload.Save(savepath)
If Err.Number <> 0 Then
Response.Write "<div style=""color:red;font-size:12px;"">出现错误: " & Err.Number & "、" & Err.Description &"<a href=""javascript:history.go(-1)"">重新上传</a></div>"
End If
If Err.Number = 8 Then
Response.Write "<div style=""color:red;font-size:12px;"">你上传的文件超过限制("& UploadLimitSize/1024 &"M)<a href=""javascript:history.go(-1)"">重新上传</a></div>"
response.end
end if
dim inputname
dim size,rs_upfile
For Each File in Upload.Files
if not CanUpload(File.ext) then
File.Delete
response.write "<div style=""color:red;font-size:12px;"">"&file.filename &"("& file.size &") 格式不正确!只支持JPG,gif,png格式的文件上传!<a href=""javascript:history.go(-1)"">重新上传</a></div>"
else
response.write "<div style=""color:green;font-size:12px;"">"&UploadFilePath&file.filename &"("& file.size &") 上传成功"%><a href="javascript:history.go(-1)">继续上传</a></div><%
Response.Write("<img src=")
Response.Write(UploadFilePath&file.filename)
Response.Write(" align=left>")
end if
next
else
%>
<%
dim SPid,PID,barref
Set UploadProgress = Server.CreateObject("Persits.UploadProgress")
SPid = UploadProgress.CreateProgressID()
PID = "PID=" & SPid
barref = "framebar.asp?to=10&" & PID
%>
<SCRIPT LANGUAGE="JavaScript">
function ShowProgress()
{
strAppVersion = navigator.appVersion;
if (document.MyForm.FILE1.value != "")
{
if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
{
winstyle = "dialogWidth=375px; dialogHeight:175px; center:yes;status:no";
window.showModelessDialog('<% = barref %>&b=IE',window,winstyle);
}
else
{
window.open('<% = barref %>&b=NN','','width=370,height=165', true);
}
}
return true;
}
function chk()
{
if (MyForm.FILE1.value=="")
{
alert("请从硬盘选择你要上传的文件...");
return false;
}
}
</SCRIPT>
<FORM NAME="MyForm" method="post" ENCTYPE="multipart/form-data" ACTION="?<% = PID %>&act=upload" OnSubmit="return ShowProgress();">
<INPUT NAME="FILE1" TYPE="FILE" SIZE="16"> <input name="Submit" type="submit" value="上 传" onClick="return chk()"></FORM>
<%end if%>
</body>
</html>

framebar.asp

<%@EnableSessionState=False%>
<% Response.Expires = -1 %>
<title>正在上传............</title>
<style type='text/css'>td {font-family:Tahoma; font-size: 8pt }</style>
<BODY BGCOLOR="white" scroll="NO" frameborder="NO" status="no" style="border:0px;">
<script language="JavaScript">
<!--
function Stopupload()
{
if (typeof(window.opener)!="undefined"){
try{
window.opener.document.execCommand("stop");
}
catch(e){}
}
else if(typeof(window.dialogArguments)!="undefined"){
try{
window.dialogArguments.document.execCommand("stop");
}
catch(e){}
}
window.close();
}
//-->
</script>
<IFRAME src="bar.asp?PID=<%= Request("PID") & "&to=" & Request("to") %>" title="Uploading" noresize scrolling=no
frameborder=0 framespacing=10 width=369 height=115></IFRAME>
<TABLE BORDER="0" WIDTH="100%" cellpadding="2" cellspacing="0">
<TR><TD ALIGN="center"><button onclick="Stopupload()" style="font-size:12px;">取消上传</button>
</TD></TR>
</TABLE>
</BODY>
</HTML>

bar.asp

<%@EnableSessionState=False%>
<%
Response.Expires = -1
PID = Request("PID")
TimeO = Request("to")
Set UploadProgress = Server.CreateObject("Persits.UploadProgress")
format = "<br><CENTER><b><font color=red>正在上传,请耐心等待...</font></b></CENTER><br><font color=red>%T%t%B3%T 速度:(%S/秒) 估计剩余时间:%R %r%U / %V(%P)%l%t</font>"
bar_content = UploadProgress.FormatProgress(PID, TimeO, "#334455", format)
If "" = bar_content Then
%>
<HTML>
<HEAD>
<TITLE>Upload Finished</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function CloseMe()
{
window.parent.close();
return true;
}
</SCRIPT>
</HEAD>
<BODY OnLoad="CloseMe()" BGCOLOR="white">
</BODY>
</HTML>
<%
Else ' Not finished yet
%>
<HTML>
<HEAD>
<meta HTTP-EQUIV="Refresh" CONTENT="1;URL=<%
Response.Write Request.ServerVariables("URL")
Response.Write "?to=" & TimeO & "&PID=" & PID %>">
<TITLE>Uploading Files...</TITLE>
<style type="text/css">
body,td {font-family:Tahoma; font-size: 8pt }
td.spread {font-size: 6pt; line-height:6pt }
td.brick {font-size:6pt; height:12px}
</style>
</HEAD>
<BODY BGCOLOR="menu">
<% = bar_content %>
</BODY>
</HTML>
<% End If %>

将这四个文件拷贝到同一个文件中,即可
dbserver 2005-09-09
  • 打赏
  • 举报
回复
顶!

---------------
欢迊来到麦高网-私活兼职首选平台 www.mgao.net
sharfly 2005-09-07
  • 打赏
  • 举报
回复
楼上那位大哥,辛苦你整一大段代码了,只是给点注释吧。小妹我是个asp新手啊。:(
andyguo370 2005-09-07
  • 打赏
  • 举报
回复
<SCRIPT RUNAT=SERVER LANGUAGE="JavaScript">
function getfileextraname(string_value)
{
string_value=trim_spaces(string_value);
var index=string_value.length-1;

while(index>=0&&string_value.charAt(index)!=".")
{
index--;
}

if(index!=-1)
{
return string_value.substring(index+1,string_value.length)
}
else
{
return "";
}
}

function trim_spaces(string_value)
{
var start;
var end;

start=0;
end=string_value.length-1;

while(string_value.charAt(start)==" ")
{
start++;
}

while(string_value.charAt(end)==" ")
{
end--;
}

return string_value.substring(start,end+1);
}

function get_newfilename()
{
var Date_obj=new Date();
return "File"+Date_obj.getTime();
}
</SCRIPT>

<SCRIPT RUNAT=SERVER LANGUAGE="VBScript">
Function GetFileName(FullPath)
FullPath=trim_spaces(FullPath)
IF FullPath<>"" Then
FullPath=Replace(FullPath,"/","\")
GetFileName=mid(FullPath,InStrRev(FullPath,"\")+1)
Else
GetFileName=""
End IF
End Function
</SCRIPT>

<%
Response.Buffer=True
Set Upload=Server.CreateObject("Persits.Upload.1")
Upload.SetMaxSize 1*1024*1024,True
Upload.OverwriteFiles=False
Upload.ProgressID=Request("PID")
Count=Upload.Save(Server.MapPath(FileSavePath))

FileCount=0
For Each File In Upload.Files
FileCount=FileCount+1
FileName=GetFileName(File.Path)
FileType=getfileextraname(FileName)
IF FileType<>"" Then
NewFileName=get_newfilename()&FileCount&"."&FileType
Else
NewFileName=get_newfilename()&FileCount
End IF
File.Move Server.MapPath(FileSavePath)&"\"&NewFileName

FileTypeStr=UCase(FileType)
IF FileTypeStr<>"ASP" And FileTypeStr<>"EXE" And FileTypeStr<>"COM" And FileTypeStr<>"DLL" Then
此处把文件名和文件路径写入数据库,代码你自己写吧
Else
File.Delete
End IF
Next

%>

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧