永发信息网

asp如何实现上传文件(比如说图片)功能,上传后可以显示该图片

答案:5  悬赏:40  手机版
解决时间 2021-05-07 22:50
  • 提问者网友:温旧梦泪无声
  • 2021-05-07 03:40
asp如何实现上传文件(比如说图片)功能,上传后可以显示该图片
最佳答案
  • 五星知识达人网友:舍身薄凉客
  • 2021-05-07 04:44

很简单的,你可以在网上下载个aspupload组件就可以了。

全部回答
  • 1楼网友:拾荒鲤
  • 2021-05-07 08:15
提问人的追问 2009-12-14 16:55

文件上传代码如下,我应该怎么样写到数据库中去呢?能不能提供一个这种实例给我,谢谢了!

<%
Response.Buffer = True
Server.ScriptTimeOut=9999999
On Error Resume Next
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<meta content="all" name="robots" />
<meta name="author" content="Woodeye" />
<style type="text/css">
<!--
body,input {font-size:12px;}
-->
</style>
<title>文件上传</title>
</head>
<body id="body">
<%
ExtName = "jpg,gif,png,txt,rar,zip,doc" '允许扩展名
SavePath = "UploadFile\filedown" '保存路径
If Right(SavePath,1)<>"/" Then SavePath=SavePath&"/" '在目录后加(/)
CheckAndCreateFolder(SavePath)

UpLoadAll_a = Request.TotalBytes '取得客户端全部内容
If(UpLoadAll_a>0) Then
Set UploadStream_c = Server.CreateObject("ADODB.Stream")
UploadStream_c.Type = 1
UploadStream_c.Open
UploadStream_c.Write Request.BinaryRead(UpLoadAll_a)
UploadStream_c.Position = 0

FormDataAll_d = UploadStream_c.Read
CrLf_e = chrB(13)&chrB(10)
FormStart_f = InStrB(FormDataAll_d,CrLf_e)
FormEnd_g = InStrB(FormStart_f+1,FormDataAll_d,CrLf_e)

Set FormStream_h = Server.Createobject("ADODB.Stream")
FormStream_h.Type = 1
FormStream_h.Open
UploadStream_c.Position = FormStart_f + 1
UploadStream_c.CopyTo FormStream_h,FormEnd_g-FormStart_f-3
FormStream_h.Position = 0
FormStream_h.Type = 2
FormStream_h.CharSet = "GB2312"
FormStreamText_i = FormStream_h.Readtext
FormStream_h.Close

FileName_j = Mid(FormStreamText_i,InstrRev(FormStreamText_i,"\")+1,FormEnd_g)

If(CheckFileExt(FileName_j,ExtName)) Then
SaveFile = Server.MapPath(SavePath & FileName_j)

If Err Then
Response.Write "文件上传: <span style=""color:red;"">文件上传出错!</span> <a href=""" & Request.ServerVariables("URL") &""">重新上传文件</a><br />"
Err.Clear
Else
SaveFile = CheckFileExists(SaveFile)

k=Instrb(FormDataAll_d,CrLf_e&CrLf_e)+4
l=Instrb(k+1,FormDataAll_d,leftB(FormDataAll_d,FormStart_f-1))-k-2
FormStream_h.Type=1
FormStream_h.Open
UploadStream_c.Position=k-1
UploadStream_c.CopyTo FormStream_h,l
FormStream_h.SaveToFile SaveFile,2

SaveFileName = Mid(SaveFile,InstrRev(SaveFile,"\")+1)
Response.write "文件上传: <span style=""color:red;"">" & SaveFileName & " </span>文件上传成功! <a href=""" & Request.ServerVariables("URL") &""">继续上传文件</a><br />"
End If
Else
Response.write "文件上传: <span style=""color:red;"">文件格式不正确!</span> <a href=""" & Request.ServerVariables("URL") &""">重新上传文件</a><br />"
End If

Else
%>
<script language="Javascript">
<!--
function ValidInput()
{

if(document.upform.upfile.value=="")
{
alert("请选择上传文件!")
document.upform.upfile.focus()
return false
}
return true
}
// -->
</script>
<form action='<%= Request.ServerVariables("URL") %>' method='post' name="upform" onsubmit="return ValidInput()" enctype="multipart/form-data">
文件上传:
<input type='file' name='upfile' size="40"> <input type='submit' value="上传">
</form>
<%
End if
Set FormStream_h = Nothing
UploadStream.Close
Set UploadStream = Nothing
%>
</body>
</html>
<%
'判断文件类型是否合格
Function CheckFileExt(FileName,ExtName) '文件名,允许上传文件类型
FileType = ExtName
FileType = Split(FileType,",")
For i = 0 To Ubound(FileType)
If LCase(Right(FileName,3)) = LCase(FileType(i)) then
CheckFileExt = True
Exit Function
Else
CheckFileExt = False
End if
Next
End Function

'检查上传文件夹是否存在,不存在则创建文件夹
Function CheckAndCreateFolder(FolderName)
fldr = Server.Mappath(FolderName)
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fldr) Then
fso.CreateFolder(fldr)
End If
Set fso = Nothing
End Function

'检查文件是否存在,重命名存在文件
Function CheckFileExists(FileName)
Set fso=Server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(SaveFile) Then
i=1
msg=True
Do While msg
CheckFileExists = Replace(SaveFile,Right(SaveFile,4),"_" & i & Right(SaveFile,4))
If not fso.FileExists(CheckFileExists) Then
msg=False
End If
i=i+1
Loop
Else
CheckFileExists = FileName
End If
Set fso=Nothing
End Function
%>

这是一个完整的上传代码! 希望有点帮助!

  • 2楼网友:刀戟声无边
  • 2021-05-07 06:40

最简单好用的ASP无组件上传,你搜索“风声无组件上传”现在是2.11版

上传后要立即显示的话,你就必须把上传返回的图片URL用javascript赋值给img标签的src属性!

  • 3楼网友:独钓一江月
  • 2021-05-07 05:53

你搜索“无组件上传 asp”很多源代码。

要在这说清楚也比较难。你下个代码看看研究研究! http://down.chinaz.com/class/20_1.htm这里有很多很好的上传代码!也很简单!

祝你进步!

  • 4楼网友:人间朝暮
  • 2021-05-07 05:29

上传操作相对比较复杂,

一般利用无组件上传,你可以去下载个用的比较多的化镜无组件上传源码,

这个适合学习用

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯