data body of request using a php proxy
I want to use a php proxy to resolve the cross domain problem during uploading file. In the script i used php curl to forward request and response, but i don't know how to forward the request body to the server when the request body is multipart/format-data. file_get_contents('php://input') will be null when the Content-Type header is "multipart/form-data". And when using curl_setopt( $ch, CURLOPT_POSTFIELDS, $_POST) , the Content-Disposition in request body could be sent, while the real data of file could not.
My request body is like this:
------WebKitFormBoundaryd0tvwIvevPV4VTlP
Content-Disposition: form-data; name="name"
nbzdds.mp3
------WebKitFormBoundaryd0tvwIvevPV4VTlP
Content-Disposition: form-data; name="chunk"
15
------WebKitFormBoundaryd0tvwIvevPV4VTlP
Content-Disposition: form-data; name="chunks"
44
497161
------WebKitFormBoundaryd0tvwIvevPV4VTlP
Content-Disposition: form-data; name="file"; filename="blob"
Content-Type: application/octet-stream
��v;"S�;-�mGu#...
.
.
.
Ideally you would want to store the uploaded file locally, use curl's FTP function to upload the file from the script server to the storage server, then delete the cached file on the script server.
If this isn't possible, send a curl request to a script on the remote fileserver, which should download the file from the original server to itself.
It might not be quite as fast as sending the uploaded files directly to the remote fileserver, but it's essentially the same except you're caching the file locally while it uploads to the remote server. This might be better anyway because the uploaded data won't be stored in your server's ram for the entire operation, which could have lead to out of memory problems if lots of files were being uploaded simultaneously.
链接地址: http://www.djcxy.com/p/48896.html上一篇: PHP cURL提交POST数据,multipart / form
下一篇: 使用php代理的请求的数据体