所属类别:Asp
文章作者:未知
特别推荐:免费发布信息 承包关键词~~抢爆了!HOT!
图片上传<!--function xxg(){ if (frmadd.file1.value=="" && frmadd.file2.value=="" && frmadd.file3.value=="" && frmadd.file4.value=="" && frmadd.file5.value=="") {alert("图片路径?");return false; } return true; }//--> ----------------------------add.asp------------------------------------<!--#include file="conn.asp"--><!--#INCLUDE FILE="upload.inc"-->图片上传<%'图片管理程序---上传代码开始function lngConvert2(strTemp)str1=leftb(strTemp,1)str2=rightb(strTemp,1)lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))end functionfunction lngConvert(strTemp)str1=leftb(strTemp,1)str2=rightb(strTemp,1)len1=ascb(str1)len2=ascb(str2)lngConvert = clng(ascb(str1) + ascb(str2) * 256)end functionDim FormData,FormSizeFormSize=Request.TotalBytesFormData=Request.BinaryRead(FormSize)Set Fields = GetUpload(FormData)for i=1 to 5 '获得图片的宽度和高度If Fields("file"&i).FileName<>"" and Fields("file"&i).value<>"" Thentempstr=Leftb(Fields("file"&i).Value,10)tstr=chrb(255)&chrb(216)&chrb(255)&chrb(224)&chrb(0)&chrb(16)&chrb(74)&chrb(70)&chrb(73)&chrb(70)flag=1if strcomp(tempstr,tstr,0)=0 thenlngSize = len(fields("file"&i).value)flgFound = 0strTarget = chrb(255) & chrb(216) & chrb(255) 'JPGflgFound = instrb(fields("file"&i).value, strTarget)if flgFound = 0 thenresponse.write "图片上传有可能错误!是否继续上传?(图像也许没有经过处理)"response.write "是图片上传否"response.endend ifstrImageType = "JPG"lngPos = flgFound + 2ExitLoop = falsedo while ExitLoop = False and lngPos < lngSizedo while ascb(midb(fields("file"&i).value, lngPos, 1)) = 255 and lngPos < lngSizelngPos = lngPos + 1loopif ascb(midb(fields("file"&i).value, lngPos, 1)) < 192 or ascb(midb(fields("file"&i).value, lngPos, 1)) > 195 thenlngMarkerSize = lngConvert2(midb(fields("file"&i).value, lngPos + 1, 2))lngPos = lngPos + lngMarkerSize + 1elseExitLoop = Trueend ifloopheight = lngConvert2(midb(fields("file"&i).value, lngPos +4, 2))width = lngConvert2(midb(fields("file"&i).value, lngPos +6, 2))flag=2elseflag=0end ifif flag<>2 thentempstr=Leftb(Fields("file"&i).Value,6)tstr=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(57)&chrb(97)tstr2=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(55)&chrb(97)if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 thenwidth=lngConvert(midb(fields("file"&i).value,7,2))height=lngConvert(midb(fields("file"&i).value,9,2))flag=2elseflag=0end ifend ifif flag<>2 thentempstr=Leftb(Fields("file"&i).Value,2)tstr=chrb(66)&chrb(77) 'BMPif strcomp(tempstr,tstr,0)=0 thenwidth=lngConvert(midb(fields("file"&i).value,19,2))height=lngConvert(midb(fields("file"&i).value,23,2))flag=2elseflag=0end ifend ifif flag<>2 thentempstr=Leftb(Fields("file"&i).Value,4)tstr=chrb(137)&chrb(80)&chrb(78)&chrb(71) 'PNGif strcomp(tempstr,tstr,0)=0 thenwidth = lngConvert2(midb(fields("file"&i).value, 19, 2))height = lngConvert2(midb(fields("file"&i).value, 23, 2))flag=2elseflag=0end ifend ifif flag>0 thenSet rs = Server.CreateObject("ADODB.Recordset")sql="select * from pho where id is null"rs.open sql,conn,1,3fieldsdata=Array("dandt","width","height","photo")valuesdata=Array(now,width,height,"")rs.addnew fieldsdata,valuesdataset field=rs.fields("photo")field.appendchunk Fields("file"&i).Valuettt=replace(Fields("file"&i).Value,"'","''")Rs.Updaters.closeset rs=nothingelseresponse.write "alert('图像格式不对,不能保存图像.请经过处理后再上传!');this.location.href='add.asp';"response.End()end ifelseend ifnextsql3="select * from pho where photo=''"set rs3=server.CreateObject("adodb.recordset")rs3.open sql3,conn,1,3if (not rs3.eof) or (not rs3.bof) then conn.execute("delete * from pho where photo=''")end ifrs3.closeset rs3=nothingresponse.write "图片上传成功!是否继续上传?"response.write "是图片上传否"response.endconnclose%>--------------------------------------upload.inc------------Function GetUpload(FormData)Dim DataStart,DivStr,DivLen,DataSize,FormFieldData''分隔标志串(+CRLF)DivStr = LeftB(FormData,InStrB(FormData,str2bin(VbCrLf)) + 1)''分隔标志串长度DivLen = LenB(DivStr)PosOpenBoundary = InStrB(FormData,DivStr)PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)Set Fields = CreateObject("Scripting.Dictionary")While PosOpenBoundary > 0 And PosCloseBoundary > 0''name起始位置(name="xxxxx"),加6是因为[name="]长度为6FieldNameStart = InStrB(PosOpenBoundary,FormData,str2bin("name=")) + 6FieldNameSize = InStrB(FieldNameStart,FormData,ChrB(34)) - FieldNameStart ''(")的ASC值=34FormFieldName = bin2str(MidB(FormData,FieldNameStart,FieldNameSize))''filename起始位置(filename="xxxxx")FieldFileNameStart = InStrB(PosOpenBoundary,FormData,str2bin("filename=")) + 10If FieldFileNameStart < PosCloseBoundary And FieldFileNameStart > PosopenBoundary ThenFieldFileNameSize = InStrB(FieldFileNameStart,FormData,ChrB(34)) - FieldFileNameStart ''(")的ASC值=34FormFileName = bin2str(MidB(FormData,FieldFileNameStart,FieldFileNameSize))ElseFormFileName = ""End If''Content-Type起始位置(Content-Type: xxxxx)FieldFileCTStart = InStrB(PosOpenBoundary,FormData,str2bin("Content-Type:")) + 14If FieldFileCTStart < PosCloseBoundary And FieldFileCTStart > PosOpenBoundary ThenFieldFileCTSize = InStrB(FieldFileCTStart,FormData,str2bin(VbCrLf & VbCrLf)) - FieldFileCTStartFormFileCT = bin2str(MidB(FormData,FieldFileCTStart,FieldFileCTSize))ElseFormFileCT = ""End If''数据起始位置:2个CRLF开始DataStart = InStrB(PosOpenBoundary,FormData,str2bin(VbCrLf & VbCrLf)) + 4If FormFileName <> "" Then''数据长度,减1是因为数据文件的存取字节数问题(可能是AppendChunk方法的问题):''由于字节数为奇数的图象存到数据库时会去掉最后一个字符导致图象不能正确显示,''字节数为偶数的数据文件就不会出现这个问题,因此必须保持字节数为偶数。DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 1FormFieldData = MidB(FormData,DataStart,DataSize)Else''数据长度,减2是因为分隔标志串前有一个CRLFDataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 2FormFieldData = bin2str(MidB(FormData,DataStart,DataSize))End If''建立一个Dictionary集存储Form中各个Field的相关数据Set Field = CreateUploadField()Field.Name = FormFieldNameField.FilePath = FormFileNameField.FileName = GetFileName(FormFileName)Field.ContentType = FormFileCTField.Length = LenB(FormFieldData)Field.Value = FormFieldDataFields.Add FormFieldName, FieldPosOpenBoundary = PosCloseBoundaryPosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)WendSet GetUpload = FieldsEnd Function''把二进制字符串转换成普通字符串函数Function bin2str(binstr)Dim varlen,clow,ccc,skipflag''中文字符Skip标志skipflag=0ccc = ""If Not IsNull(binstr) Thenvarlen=LenB(binstr)For i=1 To varlenIf skipflag=0 Thenclow = MidB(binstr,i,1)''判断是否中文的字符If AscB(clow) > 127 Then''AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))skipflag=1Elseccc = ccc & Chr(AscB(clow))End IfElseskipflag=0End IfNextEnd Ifbin2str = cccEnd Function''把普通字符串转成二进制字符串函数Function str2bin(varstr)str2bin=""For i=1 To Len(varstr)varchar=mid(varstr,i,1)varasc = Asc(varchar)'' asc对中文字符求出来的值可能为负数,'' 加上65536就可求出它的无符号数值'' -1在机器内是用补码表示的0xffff,'' 其无符号值为65535,65535=-1+65536'' 其他负数依次类推。If varasc<0 Thenvarasc = varasc + 65535End If''对中文的处理:把双字节低位和高位分开If varasc>255 Thenvarlow = Left(Hex(Asc(varchar)),2)varhigh = right(Hex(Asc(varchar)),2)str2bin = str2bin & chrB("&H" & varlow) & chrB("&H" & varhigh)Elsestr2bin = str2bin & chrB(AscB(varchar))End IfNextEnd Function''取得文件名(去掉Path)Function GetFileName(FullPath)If FullPath <> "" ThenFullPath = StrReverse(FullPath)FullPath = Left(FullPath, InStr(1, FullPath, "\") - 1)GetFileName = StrReverse(FullPath)ElseGetFileName = ""End IfEnd Functionfunction CreateUploadField(){ return new uf_Init() }function uf_Init(){this.Name = nullthis.FileName = nullthis.FilePath = nullthis.ContentType = nullthis.Value = nullthis.Length = null}关闭本页
相关信息· 软件开发项目控制浅谈
· 如何用老奔腾机和Linux构建防火墙
· CPU是越高越好吗?
· 操作系统任务管理器应用技巧四则
108890
19852
