We successfully set up image uploading on our server with nginx. Everything gets posted to /upload and then redirects to /file for processing. The file gets uploaded and stored, but there are headers at the top of the file.
------WebKitFormBoundaryqUwBABts5uiLHgDN
Content-Disposition: form-data; name="picture"; filename="coldplay.jpg"
Content-Type: image/jpeg
What am I to do with this? Do I strip these headers out with PHP and then save the file again?
Is uploading files with these headers expected behavior?
Here is the form:
<form action="/upload/" id="upload3" method="post">
<input type="file" id="file" name="picture" value=""/>
<input type="submit" onclick="return uploadFiles(this.form);">
</form>
and js:
<script type="text/javascript">
function uploadFiles(form) {
var formData = new FormData(form);
var url = "/upload/";
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.onload = function(e) {
if (this.status == 200) {
console.log(this.responseText);
}
};
xhr.send(formData); // multipart/form-data
return false;
}
</script>
I'm using these lines of code to strip the first four lines from our uploaded image files. I found it somewhere on SO and it works great -- unfortunately I don't know where it was.
$line_to_strip = 4;
$new_file = new SplFileObject($file_full_new, 'w');
foreach (new LimitIterator(new SplFileObject($file_full), $line_to_strip) as $line)
$new_file->fwrite($line);
I don't know if this is our permanent solution, however.