求教asp上传的文件读写原理。。。

usualwyy 2009-09-05 07:38:27
根据我理解过程应该是这样的: 从客户端把二进制文件转换成字符串,然后流到服务器上用ADODB.Stream再转换成二进制文件保存,中间从客户端到服务器的传递过程一直是字符串

这样对么?为什么我在写VB模拟表单上传文件的时候,把文件用二进制读取,然后转换成字符串POST总是没发成功。。。

我的文件读取+字符串转换模块如下

Public Function BinaryToString(ByVal BinaryStr As Variant) As String
'On Error Resume Next
Dim lnglen As Long
Dim tmpBin As Variant
Dim strC As String
Dim skipflag As Long
Dim i As Long
skipflag = 0
strC = ""

If Not IsNull(BinaryStr) Then
lnglen = LenB(BinaryStr)
For i = 1 To lnglen
If skipflag = 0 Then
tmpBin = MidB(BinaryStr, i, 1)
If AscB(tmpBin) > 127 Then
strC = strC & Chr(AscW(MidB(BinaryStr, i + 1, 1) & tmpBin))
skipflag = 1
Else
strC = strC & Chr(AscB(tmpBin))
End If
Else
skipflag = 0
End If
Next
End If
BinaryToString = strC
End Function


Public Function Getfile(FileName As String)
Dim DAT() As Byte
Dim FileSize As Long '文件长度

FileSize = FileLen(FileName) '获取文件长度
ReDim DAT(FileSize - 1) As Byte
Open FileName For Binary As #1
Get #1, , DAT
Close
Getfile = BinaryToString(DAT)
End Function
...全文
171 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mrshelly 2009-09-06
  • 打赏
  • 举报
回复
可以是 Byte 可以是 String

不过,最推荐的是 base64 string

如 hookee 所讲.. 你的问题在 RFC 文档中都有解答的.你按 RFC 文档组织就OK了.
usualwyy 2009-09-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 http://www.ietf.org/rfc/rfc1867.txt 的内容:]
Content-type: multipart/form-data, boundary=AaB03x

--AaB03x
content-disposition: form-data; name="field1"

Joe Blow
--AaB03x
content-disposition: form-data; name="pics"; filename="file1.txt"
Content-Type: text/plain

... contents of file1.txt ...
--AaB03x--


[/Quote]

这种数据包结构我太清楚不过了,但是想知道的是
content-disposition: form-data; name="pics"; filename="file1.txt"
Content-Type: text/plain

--AaB03x--
之间的文件数据是什么结构?Byte还是String.....
hookee 2009-09-05
  • 打赏
  • 举报
回复
具体格式可参考HTTP上传的 RFC http://www.ietf.org/rfc/rfc1867.txt
usualwyy 2009-09-05
  • 打赏
  • 举报
回复
来个高手给我解答下哇 @。@

28,406

社区成员

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

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