So I want users to be able to upload big files without having to worry about the post max size values. The alternative is using PUT and send a file as raw data. When using jquery I can do this:
var data = new FormData();
jQuery.each($('#file_upload')[0].files, function(i, file) {
data.append('file-'+i, file);
});
$.ajax({
url: 'upload.php?filename=test.pdf',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'PUT',
});
In PHP I can do this:
$f = fopen($_GET['filename'], "w");
$s = fopen("php://input", "r");
while($kb = fread($s, 1024))
{
fwrite($f, $kb, 1024);
}
fclose($f);
fclose($s);
Header("HTTP/1.1 201 Created");
I am not doing:
$client_data = file_get_contents("php://input");
Since putting the whole file into a variable will surely fill up all memory when uploading huge files.
The thing I cannot figure out is how to write the file data without the form boundaries. Right now it writes at the top of the file something like this:
------WebKitFormBoundaryVz0ZGHLGxBOCUVQG
Content-Disposition: form-data; name="file-0"; filename="somename.pdf"
Content-Type: application/pdf
and at the bottom something like this:
------WebKitFormBoundaryVz0ZGHLGxBOCUVQG--
So I need to parse the data. But for that I need to read the whole data stream into memory and with large video files I don't want to do that. I did read something about maybe creating a php://temp stream. But no luck yet with that. How can I write just the content to a file, without the boundary header? And without first pumping all the data into a variable?