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?