0

I'm uploading via XMLHttpRequest and FormData, and PHP is putting the stream into a file, however, the file includes the Content Boundaries, thus breaking the file.

Anything obvious I am doing wrong?

Request:

Request Method:PUT
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:11284137
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryPCL6dJMBjnsguCO9
Cookie:language=en; user=e4f383eb3cf900b61cae25d1dd24c3d1; CP=*; __utma=137079138.41499654.1373408305.1373408305.1373475669.2; __utmz=137079138.1373408305.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=icdrjtchkdik6pcs0u2ajdsrl2
DNT:1
Host:www.page.com
Origin:https://groups.google.com
Pragma:no-cache
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36
Request Payload
------WebKitFormBoundaryPCL6dJMBjnsguCO9
Content-Disposition: form-data; name="userfile"; filename="blob"
Content-Type: image/png


------WebKitFormBoundaryPCL6dJMBjnsguCO9--

PHP side

 file_put_contents(
    $filepath,
    fopen('php://input', 'r')
 );

 exit();

JS side

var formData = new FormData();
formData.append('userfile',blob);
var xhr = XMLHttpRequest();
xhr.open('PUT','http://www.page.com/',true);
xhr.send(formData);

The file is uploaded successfully, however the image uploaded is broken, because it includes the boundary before and after the binary data. Shouldn't PHP do this automagically?

4

1 回答 1

1

Multipart data is handled by PHP only on POST requests. With PUT you have direct access to bytestream and you need to handle it for yourself.

If something changes, this bug report / feature request will be closed

于 2013-07-15T23:59:45.197 回答