无组件上传图片到数据库中,asp解决方案(2)
作者:扬子 来源:动网 发布时间:2007-08-03 13:22:00
标签:上传,无组件
fupload.inc
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
’限制上传图片大小
Dim UploadSizeLimit
’********************************** 得到上传数据 **********************************
Function GetUpload()
Dim Result
Set Result = Nothing
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then ’Request method must be "POST"
Dim CT, PosB, Boundary, Length, PosE
CT = Request.ServerVariables("HTTP_Content_Type") ’reads Content-Type header
If LCase(Left(CT, 19)) = "multipart/form-data" Then ’Content-Type header must be "multipart/form-data"
’This is upload request.
’Get the boundary and length from Content-Type header
PosB = InStr(LCase(CT), "boundary=") ’Finds boundary
If PosB > 0 Then Boundary = Mid(CT, PosB + 9) ’Separetes boundary
Length = CLng(Request.ServerVariables("HTTP_Content_Length")) ’Get Content-Length header
if "" & UploadSizeLimit<>"" then
UploadSizeLimit = clng(UploadSizeLimit)
if Length > UploadSizeLimit then
’ on error resume next ’Clears the input buffer
’ response.AddHeader "Connection", "Close"
’ on error goto 0
Request.BinaryRead(Length)
Err.Raise 2, "GetUpload", "Upload size " & FormatNumber(Length,0) & "B exceeds limit of " & FormatNumber(UploadSizeLimit,0) & "B"
exit function
end if
end if
If Length > 0 And Boundary <> "" Then ’Are there required informations about upload ?
Boundary = "--" & Boundary
Dim Head, Binary
Binary = Request.BinaryRead(Length) ’Reads binary data from client
’Retrieves the upload fields from binary data
Set Result = SeparateFields(Binary, Boundary)
Binary = Empty ’Clear variables
Else
Err.Raise 10, "GetUpload", "Zero length request ."
End If
Else
Err.Raise 11, "GetUpload", "No file sent."
End If
Else
Err.Raise 1, "GetUpload", "Bad request method."
End If
Set GetUpload = Result
End Function
Function SeparateFields(Binary, Boundary)
Dim PosOpenBoundary, PosCloseBoundary, PosEndOfHeader, isLastBoundary
Dim Fields
Boundary = StringToBinary(Boundary)
PosOpenBoundary = InstrB(Binary, Boundary)
PosCloseBoundary = InstrB(PosOpenBoundary + LenB(Boundary), Binary, Boundary, 0)
Set Fields = CreateObject("Scripting.Dictionary")
Do While (PosOpenBoundary > 0 And PosCloseBoundary > 0 And Not isLastBoundary)
’Header and file/source field data
Dim HeaderContent, FieldContent
’Header fields
Dim Content_Disposition, FormFieldName, SourceFileName, Content_Type
’Helping variables
Dim Field, TwoCharsAfterEndBoundary
’Get end of header
PosEndOfHeader = InstrB(PosOpenBoundary + Len(Boundary), Binary, StringToBinary(vbCrLf + vbCrLf))
’Separates field header
HeaderContent = MidB(Binary, PosOpenBoundary + LenB(Boundary) + 2, PosEndOfHeader - PosOpenBoundary - LenB(Boundary) - 2)
’Separates field content
FieldContent = MidB(Binary, (PosEndOfHeader + 4), PosCloseBoundary - (PosEndOfHeader + 4) - 2)
’Separates header fields from header
GetHeadFields BinaryToString(HeaderContent), Content_Disposition, FormFieldName, SourceFileName, Content_Type
’Create one field and assign parameters
Set Field = CreateUploadField()
Field.Name = FormFieldName
Field.ContentDisposition = Content_Disposition
Field.FilePath = SourceFileName
Field.FileName = GetFileName(SourceFileName)
Field.ContentType = Content_Type
Field.Value = FieldContent
Field.Length = LenB(FieldContent)
Fields.Add FormFieldName, Field
’Is this ending boundary ?
TwoCharsAfterEndBoundary = BinaryToString(MidB(Binary, PosCloseBoundary + LenB(Boundary), 2))
’Binary.Mid(PosCloseBoundary + Len(Boundary), 2).String
isLastBoundary = TwoCharsAfterEndBoundary = "--"
If Not isLastBoundary Then ’This is not ending boundary - go to next form field.
PosOpenBoundary = PosCloseBoundary
PosCloseBoundary = InStrB(PosOpenBoundary + LenB(Boundary), Binary, Boundary )
End If
Loop
Set SeparateFields = Fields
End Function
’********************************** Utilities **********************************
Function BinaryToString(str)
strto = ""
for i=1 to lenb(str)
if AscB(MidB(str, i, 1)) > 127 then
strto = strto & chr(Ascb(MidB(str, i, 1))*256+Ascb(MidB(str, i+1, 1)))
i = i + 1
else
strto = strto & Chr(AscB(MidB(str, i, 1)))
end if
next
BinaryToString=strto
End Function
Function StringToBinary(String)
Dim I, B
For I=1 to len(String)
B = B & ChrB(Asc(Mid(String,I,1)))
Next
StringToBinary = B
End Function
’Separates header fields from upload header
Function GetHeadFields(ByVal Head, Content_Disposition, Name, FileName, Content_Type)
Content_Disposition = LTrim(SeparateField(Head, "content-disposition:", ";"))
Name = (SeparateField(Head, "name=", ";")) ’ltrim
If Left(Name, 1) = """" Then Name = Mid(Name, 2, Len(Name) - 2)
FileName = (SeparateField(Head, "filename=", ";")) ’ltrim
If Left(FileName, 1) = """" Then FileName = Mid(FileName, 2, Len(FileName) - 2)
Content_Type = LTrim(SeparateField(Head, "content-type:", ";"))
End Function
’Separets one filed between sStart and sEnd
Function SeparateField(From, ByVal sStart, ByVal sEnd)
Dim PosB, PosE, sFrom
sFrom = LCase(From)
PosB = InStr(sFrom, sStart)
If PosB > 0 Then
PosB = PosB + Len(sStart)
PosE = InStr(PosB, sFrom, sEnd)
If PosE = 0 Then PosE = InStr(PosB, sFrom, vbCrLf)
If PosE = 0 Then PosE = Len(sFrom) + 1
SeparateField = Mid(From, PosB, PosE - PosB)
Else
SeparateField = Empty
End If
End Function
’Separetes file name from the full path of file
Function GetFileName(FullPath)
Dim Pos, PosF
PosF = 0
For Pos = Len(FullPath) To 1 Step -1
Select Case Mid(FullPath, Pos, 1)
Case "/", "\": PosF = Pos + 1: Pos = 0
End Select
Next
If PosF = 0 Then PosF = 1
GetFileName = Mid(FullPath, PosF)
End Function
</SCRIPT>
<SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
//The function creates Field object.
function CreateUploadField(){ return new uf_Init() }
function uf_Init(){
this.Name = null
this.ContentDisposition = null
this.FileName = null
this.FilePath = null
this.ContentType = null
this.Value = null
this.Length = null
}
</SCRIPT>


猜你喜欢
- 1.散点图代码# This import registers the 3D projection, but is otherwise unu
- 今天,在家试试django的model的设置,如何设置的联合主键,我经过查资料和实践,把结果记录如下:例如:class user(Model
- mysql 5.7.21 winx64免安装版配置方法,供大家参考,具体内容如下1、下载点击下载地址2、解压到目录3、配置 新建一
- 本文实例讲述了JavaScript DOM节点操作方法。分享给大家供大家参考,具体如下:使用DOM可以新建HTML元素,也可以删除已有的HT
- Timestamp只保留日期不显示时间Timestamp.date()拿到DataFrame中的一个时间戳后,加一个**.date()**即
- 一、PyTorch 检查模型梯度是否可导当我们构建复杂网络模型或在模型中加入复杂操作时,可能会需要验证该模型或操作是否可导,即模型是否能够优
- 你是怎么把密码储存到数据库里?是以纯文字的方式?你可知道这对安全的危险性?当攻击你网站的人能开启数据库浏览,以纯文字方式存在数据库里的密码一
- 使用百度地图报错BMap is not defined1、在index.html添加密钥申请:http://lbsyun.baidu.com
- 在网络上的Pandas教程中,很多都提到了如何使用Pandas将已有的数据(如csv,如hdfs等)直接加载成Pandas数据对象,然后在其
- 这两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互。但他们的功能不尽相同。举两个小例子。>>> ra
- 这篇文章主要介绍了基于Python实现ComicReaper漫画自动爬取脚本过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具
- 矛盾出来了,像我们这些小作坊,基本都是设计布局一人搞定。甚至还有加后台程序的。假设设计的时候考虑布局了,我们都有这个能力进行调整。但像大公司
- Oracle SQL语句中的Update可以和SEQUENCE联合使用,以达到更新某字段的值连续编号,而不需要使用游标去逐条遍历更新数据库记
- 1、DataFrame返回的不是对象。2、DataFrame查出来的数据返回的是一个dataframe数据集。3、DataFrame只有遇见
- 1 慢查询定义指mysql记录所有执行超过long_query_time参数设定的时间阈值的SQL语句。慢查询日志就是记录这些sql的日志。
- 前言:数据库是大多数 Web 应用的基础设施,只要想把数据存储下来,就离不开数据库,下面将一起学习一下如何给 Flask 应用添加数据库支持
- 1.基本信息Pandas 的 apply() 方法是用来调用一个函数(Python method),让此函数对数据对象进行批量处理。Pand
- var obj=document.getElementById("txtUserID") var range=obj.c
- 很多用ACCEE97开发过数据库的用户都有这种体会:要想在窗体中添加一个命令按钮实现打开通用对话框的功能真是很困难。因为ACCESS97本身
- 1. 创建主窗口上文中我们建立的图形界面程序 GUIdemo2.py,通过导入图形界面 uiDemo1.py,已经实现了主窗口的创建。1.1