为什么我上传文件到数据库后,在数据哭里看到的都是?呢,还有在数据库中文件名不全。

chinaflyfish 2005-04-27 03:18:54
大家看看我的代码
<!--#include file="ContentStr.asp"-->
<%
'函数功能,将二进制字符串转换成文本字符
function cByteString(bString)
dim index
for index=1 to LenB(bString) 'LenB上计算字节数,一个字符有2个字节表示。
bChar=midB(bString,index,1) ' bString中的取一个 字节
if(ascB(bChar)>127) then
CByteString=CByteString&chr(ascW(midB(bString,index+1,1)&bChar))
index=index+1
else
CBytString=CByteString&chr(ascB(midB(bString,index,1)))
end if
next
end function

'读取表单数据(二进制)
length=request.TotalBytes
bFileInfo=request.BinaryRead(length)
response.Write(length&"<br>")
response.Write(bFileInfo)
'读取数据后分析数据,定义CRLF标志的二进制字符串
bCRLF=chrB(13)&chrB(10)
'截取边界的二进制字符串
dividerLen=instrB(bFileInfo,bCRLF)-1 '参考instr函数
bDivider=leftB(bFileInfo,dividerLen)
'截取头部信息,并转换为文本字符串
headerLen=instrB(bFileInfo,bCRLF&bCRLF)-1
bHeader=leftB(bFileInfo,headerLen)
sHeader=cByteString(bHeader)
'提取文件名
nameStartPos=instr(sHeader,"filename="&chr(34))+len("filename="&chr(34))
nameEndPos=instr(nameStartPos,sHeader,chr(34))
fileName=mid(sHeader,nameStartPos,(nameStartPos-nameEndPos)) '取字符串中的几个字
'提取文件内容类型
typeStartPos=instr(sHeader,"Content-Type:")+len("Content-Type/:")'返回某字符串在另一字符串中第一次出现的位置
contentType=mid(sHeader,typeStartPos)
'获取文件内容(二进制形式)
contentStartPos=instrB(bFileInfo,bCRLF&bCRLF)+4
contentEndPos=instrB(contentStartPos,bFileInfo,bDivider)
bFileContent=midB(bFileInfo,contentStartPos,(contentEndPos-contentStartPos))
'将文件信息写入数据库
SqlStr="select * from UpFile"
Set Res=Server.CreateObject("ADODB.RecordSet")
Res.open SqlStr,Conn,3,2
Res.addnew
Res("FileName")=fileName
Res("FileClass")=contentType
Res("FileContent").appendChunk bFileContent
Res.update
Res.close
Set Res=nothing
Conn.close
Set Conn=nothing
Response.Write("文件:"&fileName&"成功上传到数据库!")
%>
...全文
166 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinaflyfish 2005-04-29
  • 打赏
  • 举报
回复
还是没有人回嗲
chinaflyfish 2005-04-27
  • 打赏
  • 举报
回复
<!--#include file="ContentStr.asp"-->
<%
'函数功能,将二进制字符串转换成文本字符
function cByteString(bString)
dim index
for index=1 to LenB(bString) 'LenB上计算字节数,一个字符有2个字节表示。
bChar=midB(bString,index,1) ' bString中的取一个 字节
if(ascB(bChar)>127) then
CByteString=CByteString&chr(ascW(midB(bString,index+1,1)&bChar))
index=index+1
else
CBytString=CByteString&chr(ascB(midB(bString,index,1)))
end if
next
end function

'读取表单数据(二进制)
length=request.TotalBytes
bFileInfo=request.BinaryRead(length) '读取全部文件内容,包括文件头等信息
response.Write(length&"<br>")
response.Write(bFileInfo)
response.Write("<br>")
'读取数据后分析数据,定义CRLF标志的二进制字符串
bCRLF=chrB(13)&chrB(10)
'截取边界的二进制字符串
dividerLen=instrB(bFileInfo,bCRLF)-1 '参考instr函数
bDivider=leftB(bFileInfo,dividerLen)
response.Write("bDivider:"&bDivider&"<br>")
'截取头部信息包括边界的二进制字符串,并转换为文本字符串
headerLen=instrB(bFileInfo,bCRLF&bCRLF)-1
bHeader=leftB(bFileInfo,headerLen)
sHeader=cByteString(bHeader)
response.Write(sHeader)
response.Write("<br>")
'提取文件名
nameStartPos=instr(sHeader,"filename="&chr(34))+len("filename="&chr(34))
response.Write("开始位置:"&nameStartPos&"<br>")
nameEndPos=instr(nameStartPos,sHeader,chr(34))-1
response.Write("结束位置:"&nameEndPos&"<br>")
fileName=mid(sHeader,nameStartPos,(nameStartPos-nameEndPos)) '取字符串中的几个字
'提取文件内容类型
typeStartPos=instr(sHeader,"Content-Type:")+len("Content-Type/:")'返回某字符串在另一字符串中第一次出现的位置
contentType=mid(sHeader,typeStartPos)
'获取文件内容(二进制形式)
contentStartPos=instrB(bFileInfo,bCRLF&bCRLF)+4
contentEndPos=instrB(contentStartPos,bFileInfo,bDivider)
bFileContent=midB(bFileInfo,contentStartPos,(contentEndPos-contentStartPos))
'将文件信息写入数据库
SqlStr="select * from UpFile"
Set Res=Server.CreateObject("ADODB.RecordSet")
Res.open SqlStr,Conn,3,2
Res.addnew
Res("FileName")=fileName
Res("FileClass")=contentType
Res("FileContent").appendChunk bFileContent
Res.update
Res.close
Set Res=nothing
Conn.close
Set Conn=nothing
Response.Write("文件:"&fileName&"成功上传到数据库!")
%>
1、输出的结果是 为
331
?????????????????昹????湯整瑮?獩潰楳楴湯?潦浲搭瑡?渠浡?唢?汩?瑡扡獡?映汩湥浡??尺扡?硴??潃瑮湥?祔数?整瑸瀯慬湩???????????????????????????????????????昹????湯整瑮?獩潰楳楴湯?潦浲搭瑡?渠浡?匢扵業??????????????????????昹????
bDivider:?????????????????昹???戀爀?
开始位置:10
结束位置:-1
文件:成功上传到数据库!
  • 打赏
  • 举报
回复
参考我的blog http://blog.csdn.net/liuxiaoyi666

28,406

社区成员

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

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