当前位置:首页 » 文件管理 » 无组件上传源码

无组件上传源码

发布时间: 2023-07-13 02:18:45

⑴ ASP无组件批量上传图片

使用风声无组件上传类
<%
Set myRequest=new UpLoadClass
myRequest.FileType ="gif/jpg"'"gif/jpg"
myRequest.Savepath = "pic/"
myrequest.open

sql = "select * from tab"
set rs = server.createobject("adodb.recordset")
rs.open sql,conn,1,3
rs.addNew
rs("title") = myRequest.Form("title")
rs("file1") = myRequest.Form("file1")
rs("file2") = myRequest.Form("file2")
rs.update
set rs = nothing
%>
1.文件自动上传到pic目录自按日期时间生成不重复的文件名
2.上传的文件的文件名自动生成并可这样取出
myRequest.Form("file1")
3.text框的数据这样取
myRequest.Form("title")
4.这个类的代码可在这里
<%
'*****************************图片上传类开始*******************
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 = 204800000000'0//设定上传图片大小
p_FileType = "jpg/gif"
p_SavePath = ""
p_AutoSave = 0
strDate = replace(cstr(Date()),"-","")
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

%>

⑵ ASP无组件上传源码解释

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<%If request.totalbytes>0 Then
formsize=request.totalbytes ' 取二进制流字节长度
formdata=request.binaryread(formsize) ' 读取二进制流内容
bncrlf=chrB(13)&chrB(10)
datastart=instrb(formdata,bncrlf&bncrlf)+3 ' 取二进制流文件开始位置 (两个回车换行符)
divider=leftB(formdata,instrb(formdata,bncrlf)-1) ' 定义取二进制流 Field 分隔标记 (内容为二进制)
dataend=instrb(datastart,formdata,divider)-datastart ' 取二进制流文件部分结束位置
'将文件信息保存到数据库
'Call ImgToDb() '将上传的图片以二进制保存到数据库中
Call SaveTofile() '将上传的文件保存到服务器
End If
Sub ImgToDb() '将上传的图片以二进制保存到数据库中
mydata=midb(formdata,datastart+1,dataend)'
Set conn=server.CreateObject("adodb.connection")
conn.provider="microsoft.jet.oledb.4.0"
conn.open server.mappath("book/stu.mdb")
Set rs=server.CreateObject("adodb.recordset")
rs.open "select * from img",conn,3
rs.movelast
rs.addnew
rs("img").appendchunk mydata
rs.update
response.binarywrite rs(1)
response.End
End Sub
Sub SaveTofile()'将上传的文件保存到服务器
'2.将获取的信息以二进制流文件存放 --- stm
savepath=server.mappath("images")&"\" '根据情况自己要先建立相应目录 或者开启fso自动建立
Set strm=createObject("adodb.str"&"eam")
with strm
.type=1 ' 二进制模式
.mode=3 ' 指定打开模式为读写
.open
.write formdata '写入二进制流内容
'以文本模式读取数据,用于获得提交上来的文件路径及名称等信息
.position=0 '将游标指向数据首部
.type=2 '以文本模式读取
.CharSet = "gb2312" '设置中文编码
formhead=.ReadText(datastart-1) '读取表单头部内容
End with
'2.1获取上传的文件名称filename
fullname=fRegExpSgl(formhead,true,true,true,"[\s\S]*filename\=""(.*?)""[\s\S]*","$1")
fname=Split(fullname,"\")
filename=fname(UBound(fname)) '获取到文件名
Set fso = Server.CreateObject("Scripting.File"&"System"&"Object") '判断是否与本地盘文件重名,否则重命名 XXX(1).xxx
If fso.FileExists(savepath&filename) Then
For i=1 To 999
Fxname=Split(filename,".")
Fn=Left(filename,InstrRev(filename,".")-1)
Fnx=fxname(UBound(fxname))
If Not fso.FileExists(SavePath&Fn&"("&i&")."&Fnx) Then
filename=Fn&"("&i&")."&Fnx
Exit For
End If
Next
End If
'3.从stm二进制流文件中获取有效信息 及 保存文件
Set formstrm=createOBject("adodb.str"&"eam")
with formstrm
.type=1 ' 二进制模式
.mode=3
.open
strm.position = datastart ' 指定 stm 对象的起始位置, 以变量 bStart 的值为起始位置
strm.To formstrm,dataend ' 拷贝 stm 二进制流至 fromStm 对象, 长度为 bEnd 变量的长度
.saveTofile (savepath&filename),2 ' 将信息保存到文件, 如果存在相同名称, 则覆盖
.close
end with
Set strm=Nothing
Set formstrm=Nothing
response.redirect "?upload=ok&name="&filename
End Sub function fRegExpSgl(str,glb,igc,mtl,pt,rpt)
dim re
set re=new RegExp
re.global=glb
re.ignoreCase=igc
re.multiline=mtl
re.pattern=pt
fRegExpSgl=re.replace(str,rpt)
set re=nothing
end function
%>
<html>
<body leftmargin="0" topmargin="0">
<form action="" method="post" name="form1" enctype="multipart/form-data">
<!-- enctype="multipart/form-data"不能省略,以保证提交过来的信息的正确性,可以远程提交信息 -->
<input name="FileName" type="FILE" class="tx1" size="40" style="height:22">
<input type="submit" name="Submit" value=" 上传 " style="color:red;height:22;width:70">
</form>
<%
'''测试语句:输出相关图片
If request("upload")="ok" Then
response.write "<img src=""images/"&request("name")&""">"
End If
%>
</body>
</html>
</body>
</html>

⑶ 求ASP图片上传源码,具体要求如下

<%@ language="javascript"%>
<%
var self = Request.serverVariables("SCRIPT_NAME");
if (Request.serverVariables("REQUEST_METHOD")=="POST")
{
var oo = new uploadFile();
oo.path = "../../images/swf/"; //存放路径,为空表示当前路径,默认为uploadFile
oo.named = "date"; //命名方式,date表示用日期来命名,file表示用文件名本身,默认为file
oo.ext = "all"; //允许上传的扩展名,all表示都允许,默认为态腊all
oo.over = true; //当存在相同文件名时是否覆盖,默认为false
oo.size = 1*1024*1024; //最大字节数限制,默认为1G
oo.upload();
Response.write('<script type="text/javascript">location.replace("'+self+'")<空樱/script>');
}

//ASP无组件上传类
function uploadFile()
{
var bLen = Request.totalBytes;
var bText = Request.binaryRead(bLen);
var oo = Server.createObject("ADODB.Stream");
oo.mode = 3;
this.path = "uploadFile";
this.named = "file";
this.ext = "all";
this.over = false;
this.size = 1*1024*1024*1024; //1GB

//文件上传
this.upload = function ()
{
var o = this.getInfo();
if (o.size>this.size)
{
alert("文件过大,不能上传!");
return;
}
var f = this.getFileName();
var ext = f.replace(/^.+\./,"");
if (this.ext!="all"&&!new RegExp(this.ext.replace(/,/g,"|"),"ig").test(ext))
{
alert("目前暂不支持扩展名为 "+ext+" 的文件上传!");
return;
}
if (this.named=="date")
{
var f = new Date().toLocaleString().replace(/\D/g,"") + "." + ext;
}

oo.open();
oo.type = 1;
oo.write(o.bin);
this.path = this.path.replace(/[^\帆亏滑/\\]$/,"$&/");
var fso = Server.createObject("Scripting.FileSystemObject");
if(this.path!=""&&!fso.folderExists(Server.mapPath(this.path)))
{
fso.createFolder(Server.mapPath(this.path));
}
try
{
oo.saveToFile(Server.mapPath(this.path+f),this.over?2:1);

Response.write('<script type="text/javascript">parent.form.swf_Pic.value=("images/swf/'+f+'")</script>');

alert(f);
}
catch(e)
{

alert("对不起,此文件已存在!");
}
oo.close();
delete(oo);

}

//获取二进制和文件字节数
this.getInfo = function ()
{
oo.open();
oo.type=1;
oo.write(bText);
oo.position = 0;
oo.type=2;
oo.charset="unicode";
var gbCode=escape(oo.readText()).replace(/%u(..)(..)/g,"%$2%$1");
var sPos=gbCode.indexOf("%0D%0A%0D%0A")+12;
var sLength=bLen-(gbCode.substring(0,gbCode.indexOf("%0D%0A")).length/3)-sPos/3-6;
oo.close();

oo.open();
oo.type = 1;
oo.write(bText);
oo.position=sPos/3;
var bFile=oo.read(sLength);
oo.close();

return { bin:bFile, size:sLength };
}

//获取文件名
this.getFileName = function ()
{
oo.open();
oo.type = 2;
oo.writeText(bText);
oo.position = 0;
oo.charset = "gb2312";
var fileName = oo.readText().match(/filename=\"(.+?)\"/i)[1].split("\\").slice(-1)[0];
oo.close();
return fileName;
}

function alert(msg)
{
Response.write('<script type="text/javascript">alert("'+msg+'");</script>');
}
}
%>
<body topmargin="0" marginwidth="0">

<form action="<%=self%>" method="POST" enctype="multipart/form-data" onSubmit="return (this.upFile.value!='');" name="myform" style="border: 1px solid #C0C0C0">
<input type="file" name="upFile" size="21"/>
<input type=submit name=submit value=上传 class="tx1">
</form>

热点内容
如何修改已经更改的密码 发布:2025-02-04 13:38:38 浏览:772
唐dm2021买哪个配置划算 发布:2025-02-04 13:38:38 浏览:626
真空压缩重 发布:2025-02-04 13:38:37 浏览:639
alias脚本 发布:2025-02-04 13:38:03 浏览:737
linux终端字符 发布:2025-02-04 12:52:40 浏览:734
c语言程序设计mobi 发布:2025-02-04 12:51:55 浏览:257
rsa算法c语言 发布:2025-02-04 12:50:36 浏览:783
阿里云服务器托管破解 发布:2025-02-04 12:47:43 浏览:256
汽车都有什么配置 发布:2025-02-04 12:42:51 浏览:457
ons解压密码 发布:2025-02-04 12:42:43 浏览:778