大家好我使用该代码将zip文件发送到我的服务器,从这里: https://wqweto.wordpress.com/2011/07/12/vb6-using-wininet-to-post-binary-file/
我用它将zip文件发送到我的服务器,但我的服务器端有一个无法接收我的文件的脚本,不知道问题是来自我的VBA还是我的PHP。我会告诉你两个代码,试图得到你们的帮助。非常感谢。
Public Function pvPostFile(sUrl As String, sFileName As String, Optional ByVal bAsync As Boolean) As String
'Const STR_BOUNDARY As String = "3fbd04f5-b1ed-4060-99b9-fca7ff59c113"
Dim nFile As Integer
Dim baBuffer() As Byte
Dim sPostData As String
'--- read file
nFile = FreeFile
Open sFileName For Binary Access Read As nFile
If LOF(nFile) > 0 Then
ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
Get nFile, , baBuffer
sPostData = StrConv(baBuffer, vbUnicode)
End If
Close nFile
'--- prepare body
sPostData = "Content-Disposition: form-data; filename=""" & Mid$(sFileName, InStrRev(sFileName, "\") + 1) & vbCrLf & _
"Content-Type: application/octet-stream" & vbCrLf & vbCrLf & _
sPostData & vbCrLf
'--- post
With CreateObject("MSXML2.XMLHTTP.6.0")
.Open "POST", sUrl, bAsync
.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.SetRequestHeader "Content-Type", "multipart/form-data;"
.SetRequestHeader "Name", FindLastModified
.SetRequestHeader "Connection", "close"
.Send pvToByteArray(sPostData)
If Not bAsync Then
pvPostFile = .ResponseText
End If
End With
End Function
Private Function pvToByteArray(sText As String) As Byte()
pvToByteArray = StrConv(sText, vbFromUnicode)
End Function
我的服务器端代码:
error_reporting(E_ALL);
ini_set('display_errors', '1');
$headers = getallheaders();
$input = print_r($_FILES, true);
$sDate = date('Y-m-d H:i:s');
这是我服务器端代码的一部分。但问题出在这里我认为,因为我无法通过“$ input = print_r($ _ FILES,true);”得到我的文件。 相反,我用它来接收文件,但它不应该是这样的:
$input = file_get_contents('php://input');
$i = strpos($input, "\r\n\r\n");
if ($i !== false)
$input = substr($input, $i + 4);
file_put_contents('resultado.zip', $input);