关于ASP页面中图片文件上传的问题?来者有分!!!

GoWish 2005-04-04 03:42:37
在ASP页面中如何实现图片的上传,使用有组件和无组件的方法怎么实现?哪种方法更好?
请给段code举例,谢谢!
...全文
299 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyhn168 2005-04-08
  • 打赏
  • 举报
回复
用化境上传!要源代码的话请QQ我:273308641,实现效果如:
http://www.puworld.org/pu/product_add.asp

可以直接用,不过这样做你什么都学不到,拿去研究研究吧!
GoWish 2005-04-08
  • 打赏
  • 举报
回复
在线等,请大家帮忙解决,谢谢!!!
GoWish 2005-04-08
  • 打赏
  • 举报
回复
我想使用一个text和一个butto控件来代替file控件的实现效果,主要是因为按键名称要改为
"変 更",如下:
<input type="text" name="text" id="text">
<input type="button" value="変 更" onClick="file.click();text.value=file.value;">
<input type="file" name="file" id="file" style="display:none">
但是在提交时,file.value确为"",不能正常上传文件,哪位帮忙解决,谢谢!!!

使用upload_5xsoft上传.
----------------------------------------------
提交页面的代码如下:
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title></title>
</head>
<body>
<br><hr size=1 noshadow width=300 align=left><br><br>
<%
dim upload,file,formName,formPath,iCount
set upload=new upload_5xsoft

if upload.form("filepath")="" then
set upload=nothing
else
formPath=upload.form("filepath")
if right(formPath,1)<>"\" then formPath=formPath&"\"
end if

iCount=0
for each formName in upload.objForm
response.write "form:" & formName &"=" &upload.form(formName)&"<br>"
next

for each formName in upload.objFile
set file=upload.file(formName)
if file.FileSize>0 then
response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&"!<br>"
file.SaveAs formPath&file.FileName
iCount=iCount+1
end if
set file=nothing
next

set upload=nothing
%>
</body>
</html>
aspnetonline 2005-04-07
  • 打赏
  • 举报
回复
down net
hanjie28 2005-04-07
  • 打赏
  • 举报
回复
我认为无组件好!
第一:效率不错!第二:不用担心服务器问题!第三:还是免费的!

风声无组件上传类V2.0

我一直在用!效果不错!可以加我QQ 3100974,我把例子给你传给你!
underone 2005-04-07
  • 打赏
  • 举报
回复
你为什么不用无组件的呢
个人认为无组件的好
GoWish 2005-04-07
  • 打赏
  • 举报
回复
在使用lyfupload组件上传时遇到困难,请各位帮忙解答:
1.asp
<%@ Language=VBScript%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META HTTP-EQUIV="content-type" CONTENT="text/html;charset=Shift_JIS">
<META http-equiv="Content-Style-Type" CONTENT="text/css">
<TITLE></TITLE>
</HEAD>
<BODY>
<form name="form1" id="form1" action="ftpUpLoadWrite.asp" method=post ENCTYPE="multipart/form-data">
<input type="text" name="text" id="text"><input type="button" value="変 更" onClick="file.click();text.value=file.value;">
<input type=hidden name="hidPath" id="hidPath" value="">
<br>
<br>
<input type="file" name="file" id="file">
<input type="button" name="sub" id="sub" value="UpLoad" onclick="window.document.form1.submit()">
</form>
</BODY>
</HTML>

2.ftpUpLoadWrite.asp
<%
Set obj = Server.CreateObject("LyfUpload.UploadFile")
txt = obj.Request("text")
Response.Write(txt)
ss = obj.SaveFile("file","c:\temp",true)
aa = obj.FileType("file")
if ss <> "" then
Response.Write("sucess")
else
Response.Write("fail")
end if
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="content-type" CONTENT="text/html;charset=Shift_JIS">
<META http-equiv="Content-Style-Type" CONTENT="text/css">
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<%
%>UpLoad!
</BODY>
</HTML>
upLoad时报错,报错信息为"ACCESS 拒绝处理"
coolwindkaka 2005-04-04
  • 打赏
  • 举报
回复
大把的无组件上传工具
lstup 2005-04-04
  • 打赏
  • 举报
回复
to netter2003(心里好烦):
Class upload_5xSoft 是不是组件类呀?
==========
我不是说了吗?
就是化境
kkkbs 2005-04-04
  • 打赏
  • 举报
回复
嗯嗯...无组件Class upload_5xSoft
richwong 2005-04-04
  • 打赏
  • 举报
回复
Class upload_5xSoft
乃无组上传类
GoWish 2005-04-04
  • 打赏
  • 举报
回复
to netter2003(心里好烦):
Class upload_5xSoft 是不是组件类呀?
lstup 2005-04-04
  • 打赏
  • 举报
回复
http://www.37zz.com/ShowPost.asp?id=101

就是化境了啦。
  • 打赏
  • 举报
回复
使用方法补充:
SavePath="upcpimage/"
set upload=new upload_5xsoft
set file=upload.file("file1")
if file.filesize>0 then
fileext=right(file.filename,3)
if fileext="asp" or fileext="asa" or fileext="aspx" then
response.write"<script>alert('此类文件不能上传');history.back();</script>"
response.End
end if
randomize
ranNum=int(900*rnd)+100
filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
file.Saveas Server.mappath(FileName)
'//////////////////////////////////////////////////
file1为文件域的名称
  • 打赏
  • 举报
回复
无组件一传我有:

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_5xSoft_Stream

Class upload_5xSoft

dim Form,File,Version

Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version="深圳 Version 1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
form.Add mFormName,mFormValue
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > 127 Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function

Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=nothing
End Sub


Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function

Private function toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class


Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>
GoWish 2005-04-04
  • 打赏
  • 举报
回复
最好给段无组件上传的方法,谢谢
hbhbhbhbhb1021 2005-04-04
  • 打赏
  • 举报
回复
lyfupload组件,你到网上搜下好多,自代教程
给你个例子,4个文件,这个组件服务器要注册的,需要注意的是不能用request方法了,要用组件带的那个request方法

1.asp
<form method="POST" enctype="multipart/form-data" action="demo4.asp">
<p>文本框1: <input type="text" name="text1" size="20"><br>
选择文件:<input type="file" name="file1"><br>
<input type="submit" value="上载" style="background-color: rgb(0,0,255); color: rgb(255,255,0)"> </p>
</form>

demo4.asp

<%@Language=VBScript %>
<%
FormSize = Request.TotalBytes
FormData = Request.BinaryRead( FormSize )

bncrlf=chrb(13) & chrb(10)
divider=leftb(formdata,instrb(formdata,bncrlf)-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
Image=midb(formdata,datastart,dataend)

head_version = Ascb( midb( Image,1,3 ) )
head_subversion = Ascb( midb( Image,4,3 ) )

head_width_l = Ascb( midb( Image,7,1 ) )
head_width_h = Ascb( midb( Image,8,1 ) )

head_height_l = Ascb( midb( Image,9,1 ) )
head_height_h = Ascb( midb( Image,10,1 ) )

head_colors = Ascb( midb( Image, 11, 1 ) )

head_width_h = head_width_h * 256

head_height_h = head_height_h * 256


head_colors = head_colors And &H07

Response.Write "图像大小为" & head_width_h + head_width_l & "x" & head_height_h + head_height_l & "x" & 2^( head_colors + 1 )

'设置数据库链接
strConn = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=jishu;Data Source=RD03"
session("strconn")=strConn
Set dbc = Server.CreateObject("ADODB.Connection")
dbc.open strConn
set rs=server.CreateObject("adodb.recordset")
rs.Open "SELECT * FROM product",dbc,1,3
%>
<HTML>
<BODY>
<%
Set obj = Server.CreateObject("LyfUpload.UploadFile")
obj.maxsize=2048 '设置文件上传的最大为2048个字节(2K)
obj.extname="gif"
txt = obj.request("text1") '得到form元素的值
Response.Write( "文本框1的输入值是: " & txt)
Response.Write "<br>"
ss=obj.SaveFiletodb("file1") '保存文件到服务器
aa=obj.filetype("file1") '得到文件的Content-Type


if ss= "" then
Response.Write ("文件上传失败!")
elseif ss= "0" then
Response.Write ("文件尺寸过大!")
elseif ss= "1" then
Response.Write ("文件不是gif文件!")
else
'----文件上载到数据库中---------
rs.AddNew
rs("name")=trim(aa)
rs("pic").AppendChunk obj.DBContent'BLOB数据不能直接赋值
rs.Update
rs.movelast
session("ID")=rs("ID")
rs.Close
dbc.Close
set rs=nothing
set dbc=nothing
'------------------------------上载到数据库中结束
Response.Write "选择的文件已经上载到服务器!<br>"
Response.Write("文件名:" & ss)
Response.Write("<br>Content-Type:" & aa) '得到Content-Type
Response.Write("文件大小:" & obj.FileSize)
end if

obj.about '关于LyfUploa1.0
%>
<br>
<a href="pictest.asp?ID=<%=session("ID")%>">点击此处查看上传后数据库中的GIF文件!</a>
</BODY >
</html>

pictest.asp
<%
Function SetForDisplay(field, contentType)

contentType = contentType
nFieldSize = field.ActualSize
bytes = field.GetChunk(nFieldSize)

Session("Bytes") = bytes
Session("Type") = contentType
End Function
%>

<%
sql = "select * from product where id=" & request("ID")
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = 3
strConn = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=jishu;Data Source=RD03"
oRS.Open sql, strConn

SetForDisplay oRS("pic"), "image/gif" '"image/gif" 为MIME类型
'常见文件的MIME类型
'GIF文件 "image/gif"
'BMP文件 "image/bmp"
'JPG文件 "image/jpeg"
'zip文件 "application/x-zip-compressed"
'DOC文件 "application/msword"
'文本文件 "text/plain"
'HTML文件 "text/html"
'一般文件 "application/octet-stream"
Set oRS.ActiveConnection = Nothing
%>
<img src="theImg.asp">
<%response.write(Session("Type"))%>

theImg.asp
<%
' theImg.asp proxy page
response.Expires = 0
response.Buffer = True
response.Clear
response.contentType = Session("Type")
'Response.Write(Session("ImageBytes"))
response.BinaryWrite Session("Bytes")
Session("Type") = ""
Session("Bytes") = ""
response.End
%>



lstup 2005-04-04
  • 打赏
  • 举报
回复
code网上自己down,
lstup 2005-04-04
  • 打赏
  • 举报
回复
化境,一直用得挺顺手,不用担心服务器问题

28,406

社区成员

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

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