高分求救:关于GIF,JPG,JPEG,BMP图片编码的求够

jingxiaoping 2003-12-09 11:34:43
关于上传图片时如何不用取后缀名的方法,来解决不能上传非GIF,JPG,JPEG,BMP图片的问题的求救
所以看来只能求助大家把GIF,JPG,JPEG,BMP图片的编码发布一下了,是不是很困难呀.
汗~~~~~~~~
这次开贴先开20分吧,完工之后有100相赠.
...全文
101 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
编程最光荣 2003-12-12
  • 打赏
  • 举报
回复
我看懂了!Thanks!
jingxiaoping 2003-12-12
  • 打赏
  • 举报
回复
谢谢大家,我已经找到了所有图象格式的编码了
TO:yonghengdizhen(冻结的空气中我渴望自由的呼吸)
不是能阅读英文资料,问题是我太懒了,哈哈,翻译过来的东东多容易理解呀。
上次为了搞一个东西,看英文都看到头大了。
嘿嘿,问题已经解决,结贴子了。
谢谢yonghengdizhen(冻结的空气中我渴望自由的呼吸),另开贴给你100分,三角猫20分了,最上面的朋友说的没有解决问题,这个就不能怪我了。
DeltaCat 2003-12-12
  • 打赏
  • 举报
回复
其实问题很简单的,即使用户改了文件的后缀名,文件的格式是固定的
所以,你只要判断上传文件的 CONTENT_TYPE 就OK了
JPG--- image/jpeg
GIF----image/gif
jpeg ---image/jpeg
bmp ---image/bmp

只要判断文件的 CONTENT-TYPE不是上面这四个,就不通过
yonghengdizhen 2003-12-12
  • 打赏
  • 举报
回复
to jingxiaoping(恋爱温度)
程序员必须要学会阅读英文资料,这是程序员最基本的素质要求.
如果你不能阅读英文资料,就算给你中文的,拿着也没什么用
jingxiaoping 2003-12-12
  • 打赏
  • 举报
回复
TO:yonghengdizhen(冻结的空气中我渴望自由的呼吸),谢谢,但为什么没有中文的?呼呼...
yonghengdizhen 2003-12-12
  • 打赏
  • 举报
回复
http://formats.myrice.com/tech/tech.htm
jingxiaoping 2003-12-12
  • 打赏
  • 举报
回复
顶顶顶,怎么没有人理我,这个问题真这么难吗?
jingxiaoping 2003-12-09
  • 打赏
  • 举报
回复
也许大家听得不太明白,上传格式的问题已经解决了,不过就是怕有些人为了好玩,故意将后缀名改为GIF,JPG,JPEG,BMP,导致传上来的图片看似正确,却无法显示出来的问题,所以说,需要解决这个问题的话必须得通过测试数据库存放图片的字段中是否含有GIF,JPG,JPEG,BMP标志性字符的方法,来判断此文件是否是真正的GIF,JPG,JPEG,BMP.
再一点就是因为图片是以二进制的方式读出来的,所以不管他的后缀是否是GIF,JPG,JPEG,BMP,只要是二进制中的标志性字符正确,它应该都可以读出来并显示.
麻烦有志之士再次踊跃参加.
再抛出100分,已经是220分的问题了.
momoly 2003-12-09
  • 打赏
  • 举报
回复
把这个文件,包含在上传图片的页面内。
<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>

28,407

社区成员

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

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