关于在com组件里用二进制写文件的问题
form_size = MyRequest.TotalBytes
form_data = MyRequest.BinaryRead(form_size)
bncrlf = ChrB(13) & ChrB(10)
divider = LeftB(form_data, CLng(InStrB(form_data, bncrlf)) - 1)
'------以下代码分隔出二进制的文件数据部份
start_pos = InStrB(form_data, divider) + LenB(divider) + LenB(bncrlf)
end_pos = InStrB(start_pos, form_data, divider) - LenB(bncrlf)
form_data = MidB(form_data, start_pos, end_pos - start_pos)
start_pos = InStrB(start_pos, form_data, bncrlf & bncrlf)
form_data = MidB(form_data, start_pos + LenB(bncrlf & bncrlf))
'-------以下代码将分隔出来的文件数据以vb的二进制方式写入到磁盘
Open "e:\test\test.jpg " For Binary As #1
Put #1, , form_data
Close #1
现在问题就出在写文件这部份,已经通过在浏览器中输出分隔出来的文件数据那部份,能正常显示出图像,说明分隔出来的数据是完整正确的,可为何将这部份数据写入到磁盘后,文件大小总是不正确?而且上传后的图片也不能正常显示?
我用response.BinaryWrite form_data在浏览器里输出是正常的啊?
------解决方案--------------------晕,你又开始了,好久8见啊。。。。。。这个你对比一下,用editplus打开后,能看到上传前后不一样的地方
------解决方案--------------------在最上面声明:
Private Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " (Destination As Any, Source As Any, ByVal Length As Long)
......
Dim tmp() As Byte
Dim iLen As Long
iLen = LenB(form_data)
ReDim tmp(iLen - 1)
CopyMemory tmp(0), ByVal StrPtr(form_data), iLen
Open "e:\test\test.jpg " For Binary As #1
Put #1, , tmp()
Close #1