| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 665 人关注过本帖
标题:[求助]找一个不用点上传按钮的无组件上传程序
只看楼主 加入收藏
yangliangy
Rank: 1
等 级:新手上路
帖 子:144
专家分:0
注 册:2006-6-25
收藏
 问题点数:0 回复次数:2 
[求助]找一个不用点上传按钮的无组件上传程序
一直用的无组件上传程序都是先要选择文件,再点上传(有时等它上传成功要很久).想找一个不用点上传按钮的无组件上传程序,就像有些论坛发帖时一样,上传的附件和form中的内容一起提交.
有程序的朋友能不能贴上来分享一下.
搜索更多相关主题的帖子: 上传按钮 组件上传 form 
2007-01-15 16:23
lq7350684
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:5089
专家分:98
注 册:2006-11-6
收藏
得分:0 
我有一个无组件上传图片的代码,不知道能不能改,还没仔细研究,要不你看一下能不能用,改好了以后给大家帖出来共享一下哦,呵呵.



无组件上传图片

首页index.asp
<!--#include file="conn.asp"-->
<form action="upload.asp" enctype="multipart/form-data" name="form1" method="post">
文本内容<input name="txt" type="text" value="测试">
上传文件 <input name="img" type="file">
<input type="submit" name="Submit" value="提 交">
</form><br>
<%
sqloraccess="1"'-----------1表示支持sql数据库;0表示支持access
Set rs=server.CreateObject("adodb.recordset")
sql="select * from txt"
rs.open sql,conn,1,1
Do While Not rs.eof
myimg=myimg&rs("txt")&"&nbsp;&nbsp;&nbsp;&nbsp;"&"<a href=?id="&rs("id")&"&theimg="&rs("img")&" title=""删除"">删除"&"</a>"&"&nbsp;&nbsp;"&"<br>"
myimg1=myimg1&"<img src="&rs("img")&">"&"&nbsp;&nbsp;"&"<br>"
myimg2=myimg&myimg1
rs.movenext
Loop
response.write ""&myimg2&""
'myurl="http://"&Request.ServerVariables("server_name")&Request.ServerVariables("path_info")
'aa="http://"&Request.ServerVariables("server_name")
'bb="http://"&request.servervariables("HTTP_REFERER")
'response.write ""&myurl&""&"<br>"&""&aa&""&"<br>"&""&bb&"":response.end
actionn=request.querystring("id")
actionn1=request.querystring("theimg")
If actionn<>"" and actionn1<>"" then
my=right(actionn1,InStrrev(actionn1,"/")+9)
if sqloraccess="1" then
sqll="delete txt where id="&actionn
else
sqll="delete * from txt where id="&actionn
end if
conn.execute(sqll)
thisdir=server.mappath("uploadfile")
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set fdir=fs.GetFolder(thisdir)
fs.DeleteFile ""&(""&fdir&"\"&my&"")&""
Response.write "<meta http-equiv=""Refresh"" content=""1; URL=index.asp"">删除成功"
End if
%>
upload.asp
<%
'OPTION EXPLICIT
Server.ScriptTimeOut=5000
%>
<!--#include FILE="UpLoadClass.asp"-->
<!--#include FILE="conn.asp"-->
<%
dim request1,txt,img,sql
'建立上传对象
'其中对象request1你可定义成任意字符串,只是方便引用,因为传递的参数我们习惯用request来接收,所以我们定义成request1,注意,定义成request是不行的
set request1=New UpLoadClass
'设置为手动保存模式
request1.AutoSave=2
'设置服务器文件保存路径
'这里我们是把上传的图片保存在uploadfile这个子文件夹里的
request1.SavePath="uploadfile/"
'打开对象
request1.open()
'获得照片标题
'这里的.form("pic")是指你的表单文本框name="txt"
txt=request1.Form("txt")
'设置产品小图最大为10K
'任何时候都可以重设参数,这对于你上传不止一个图片很重要
request1.MaxSize=1024000
'如果保存小图成功,系统生成目标文件名
'这里的"img"是指你的上传文件表单的名字<input name="img" type="file">
if request1.Save("img",0) then
img=request1.SavePath& request1.Form("img")
end if
'response.write img
'response.write txt
'response.end
'上传内容完成,我们并得到了文本内容:txt;上传文件的文件名(带路径):pic
'关闭对象request1
set request1=nothing

'上传内容存入数据库
sql="insert into txt(txt,img) values('"& txt &"','"& img &"')"
conn.execute(sql)
'防止重复提交,把网页转入主页
response.redirect("index.asp")
%>
uploadclass.asp
<%
Class UpLoadClass
Private p_MaxSize,p_FileType,p_SavePath,p_AutoSave,p_Error
Private objForm,binForm,binItem,strDate,lngTime
Public FormItem,FileItem
Public Property Get Version
Version="Rumor UpLoadClass Version 2.0"
End Property
Public Property Get Error
Error=p_Error
End Property
Public Property Get MaxSize
MaxSize=p_MaxSize
End Property
Public Property Let MaxSize(lngSize)
if isNumeric(lngSize) then
p_MaxSize=clng(lngSize)
end if
End Property
Public Property Get FileType
FileType=p_FileType
End Property
Public Property Let FileType(strType)
p_FileType=strType
End Property
Public Property Get SavePath
SavePath=p_SavePath
End Property
Public Property Let SavePath(strPath)
p_SavePath=replace(strPath,chr(0),"")
End Property
Public Property Get AutoSave
AutoSave=p_AutoSave
End Property
Public Property Let AutoSave(byVal Flag)
select case Flag
case 0:
case 1:
case 2:
case false:Flag=2
case else:Flag=0
end select
p_AutoSave=Flag
End Property
Private Sub Class_Initialize
p_Error = -1
p_MaxSize = 153600
p_FileType = "jpg/gif"'--------------类型
p_SavePath = ""
p_AutoSave = 0
strDate = replace(cstr(Date()),"-","")
lngTime = clng(timer()*1000)
Set binForm = Server.CreateObject("ADODB.Stream")
Set binItem = Server.CreateObject("ADODB.Stream")
Set objForm = Server.CreateObject("Scripting.Dictionary")
objForm.CompareMode = 1
End Sub
Private Sub Class_Terminate
objForm.RemoveAll
Set objForm = nothing
Set binItem = nothing
binForm.Close()
Set binForm = nothing
End Sub
Public Sub Open()
if p_Error=-1 then
p_Error=0
else
Exit Sub
end if
Dim lngRequestSize,binRequestData,strFormItem,strFileItem
Const strSplit="'"">"
lngRequestSize=Request.TotalBytes
if lngRequestSize<1 then
p_Error=4
Exit Sub
end if
binRequestData=Request.BinaryRead(lngRequestSize)
binForm.Type = 1
binForm.Open
binForm.Write binRequestData
Dim bCrLf,strSeparator,intSeparator
bCrLf=ChrB(13)&ChrB(10)
intSeparator=InstrB(1,binRequestData,bCrLf)-1
strSeparator=LeftB(binRequestData,intSeparator)
Dim p_start,p_end,strItem,strInam,intTemp,strTemp
Dim strFtyp,strFnam,strFext,lngFsiz
p_start=intSeparator+2
Do
p_end =InStrB(p_start,binRequestData,bCrLf&bCrLf)+3
binItem.Type=1
binItem.Open
binForm.Position=p_start
binForm.CopyTo binItem,p_end-p_start
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strItem=binItem.ReadText
binItem.Close()
p_start=p_end
p_end =InStrB(p_start,binRequestData,strSeparator)-1
binItem.Type=1
binItem.Open
binForm.Position=p_start
lngFsiz=p_end-p_start-2
binForm.CopyTo binItem,lngFsiz
intTemp=Instr(39,strItem,"""")
strInam=Mid(strItem,39,intTemp-39)
if Instr(intTemp,strItem,"filename=""")<>0 then
if not objForm.Exists(strInam&"_From") then
strFileItem=strFileItem&strSplit&strInam
if binItem.Size<>0 then
intTemp=intTemp+13
strFtyp=Mid(strItem,Instr(intTemp,strItem,"Content-Type: ")+14)
strTemp=Mid(strItem,intTemp,Instr(intTemp,strItem,"""")-intTemp)
intTemp=InstrRev(strTemp,"\")
strFnam=Mid(strTemp,intTemp+1)
objForm.Add strInam&"_Type",strFtyp
objForm.Add strInam&"_Name",strFnam
objForm.Add strInam&"_Path",Left(strTemp,intTemp)
objForm.Add strInam&"_Size",lngFsiz
if Instr(intTemp,strTemp,".")<>0 then
strFext=Mid(strTemp,InstrRev(strTemp,".")+1)
else
strFext=""
end if
if left(strFtyp,6)="image/" then
binItem.Position=0
binItem.Type=1
strTemp=binItem.read(10)
if strcomp(strTemp,chrb(255) & chrb(216) & chrb(255) & chrb(224) & chrb(0) & chrb(16) & chrb(74) & chrb(70) & chrb(73) & chrb(70),0)=0 then
if Lcase(strFext)<>"jpg" then strFext="jpg"
binItem.Position=3
do while not binItem.EOS
do
intTemp = ascb(binItem.Read(1))
loop while intTemp = 255 and not binItem.EOS
if intTemp < 192 or intTemp > 195 then
binItem.read(Bin2Val(binItem.Read(2))-2)
else
Exit do
end if
do
intTemp = ascb(binItem.Read(1))
loop while intTemp < 255 and not binItem.EOS
loop
binItem.Read(3)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,8),chrb(137) & chrb(80) & chrb(78) & chrb(71) & chrb(13) & chrb(10) & chrb(26) & chrb(10),0)=0 then
if Lcase(strFext)<>"png" then strFext="png"
binItem.Position=18
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
binItem.Read(2)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(57) & chrb(97),0)=0 or strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(55) & chrb(97),0)=0 then
if Lcase(strFext)<>"gif" then strFext="gif"
binItem.Position=6
objForm.Add strInam&"_Width",BinVal2(binItem.Read(2))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(2))
elseif strcomp(leftB(strTemp,2),chrb(66) & chrb(77),0)=0 then
if Lcase(strFext)<>"bmp" then strFext="bmp"
binItem.Position=18
objForm.Add strInam&"_Width",BinVal2(binItem.Read(4))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(4))
end if
end if
objForm.Add strInam&"_Ext",strFext
objForm.Add strInam&"_From",p_start
intTemp=GetFerr(lngFsiz,strFext)
if p_AutoSave<>2 then
objForm.Add strInam&"_Err",intTemp
if intTemp=0 then
if p_AutoSave=0 then
strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
end if
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
objForm.Add strInam,strFnam
end if
end if
else
objForm.Add strInam&"_Err",-1
end if
end if
else
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strTemp=binItem.ReadText
if objForm.Exists(strInam) then
objForm(strInam) = objForm(strInam)&","&strTemp
else
strFormItem=strFormItem&strSplit&strInam
objForm.Add strInam,strTemp
end if
end if
binItem.Close()
p_start = p_end+intSeparator+2
loop Until p_start+3>lngRequestSize
FormItem=split(strFormItem,strSplit)
FileItem=split(strFileItem,strSplit)
End Sub
Private Function GetTimeStr()
lngTime=lngTime+1
GetTimeStr=strDate&lngTime
End Function
Private Function GetFerr(lngFsiz,strFext)
dim intFerr
intFerr=0
if lngFsiz>p_MaxSize and p_MaxSize>0 then
if p_Error=0 or p_Error=2 then p_Error=p_Error+1
intFerr=intFerr+1
end if
if Instr(1,LCase("/"&p_FileType&"/"),LCase("/"&strFext&"/"))=0 and p_FileType<>"" then
if p_Error<2 then p_Error=p_Error+2
intFerr=intFerr+2
end if
GetFerr=intFerr
End Function
Public Function Save(Item,strFnam)
Save=false
if objForm.Exists(Item&"_From") then
dim intFerr,strFext
strFext=objForm(Item&"_Ext")
intFerr=GetFerr(objForm(Item&"_Size"),strFext)
if objForm.Exists(Item&"_Err") then
if intFerr=0 then
objForm(Item&"_Err")=0
end if
else
objForm.Add Item&"_Err",intFerr
end if
if intFerr<>0 then Exit Function
if VarType(strFnam)=2 then
select case strFnam
case 0:strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
case 1:strFnam=objForm(Item&"_Name")
end select
end if
binItem.Type = 1
binItem.Open
binForm.Position = objForm(Item&"_From")
binForm.CopyTo binItem,objForm(Item&"_Size")
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
binItem.Close()
if objForm.Exists(Item) then
objForm(Item)=strFnam
else
objForm.Add Item,strFnam
end if
Save=true
end if
End Function
Public Function GetData(Item)
GetData=""
if objForm.Exists(Item&"_From") then
if GetFerr(objForm(Item&"_Size"),objForm(Item&"_Ext"))<>0 then Exit Function
binForm.Position = objForm(Item&"_From")
GetData=binFormStream.Read(objForm(Item&"_Size"))
end if
End Function
Public Function Form(Item)
if objForm.Exists(Item) then
Form=objForm(Item)
else
Form=""
end if
End Function
Private Function BinVal2(bin)
dim lngValue,i
lngValue = 0
for i = lenb(bin) to 1 step -1
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
BinVal2=lngValue
End Function
Private Function Bin2Val(bin)
dim lngValue,i
lngValue = 0
for i = 1 to lenb(bin)
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
Bin2Val=lngValue
End Function
End Class
%>
保存图片文件夹uploadfile
2007-01-15 16:47
yangliangy
Rank: 1
等 级:新手上路
帖 子:144
专家分:0
注 册:2006-6-25
收藏
得分:0 
谢谢,我去看一下

http://www./blog  我的小站
2007-01-20 10:33
快速回复:[求助]找一个不用点上传按钮的无组件上传程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019005 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved