Viewed   197 times

I'm trying to upload a file larger than 2GB to a local PHP 5.3.4 server. I've set the following server variables:

memory_limit = -1
post_max_size = 9G
upload_max_filesize = 5G

However, in the error_log I found:

PHP Warning: POST Content-Length of 2120909412 bytes exceeds the limit of 1073741824 bytes in Unknown on line 0

Can anyone tell me why this keeps failing please?



Maybe this can come from apache limitations on POST size:

It seems this limitation on 2Gb can be greater on 64bits installations, maybe. And i'm not sure setting 0 in this directove does not reach the compilation limit. see for examples that thread:

Then do not forget to alter as well the max_input_time in PHP.

But you are reaching high limits :-) maybe you could try a rich client (flash? js?) on the browser side, doing the transfer in chunks or some sort of FTP things, with progress indicators for the user.

Wednesday, October 5, 2022

For a simple fix that would require no server side changes, I would use the HTML5 File API to check the size of the file before uploading. If it exceeds the known limit, then cancel the upload. I believe something like this would work:

function on_submit()
  if (document.getElementById("upload").files[0].size > 666)
    alert("File is too big.");
    return false;

  return true;

<form onsubmit="return on_submit()">
<input id="upload" type="file" />

Obviously it's just a skeleton of an example, and not every browser supports this. But it wouldn't hurt to use this, as it could be implemented in such a way that it gracefully degrades into nothing for older browsers.

Of course this doesn't solve the issue, but it will at least keep a number of your users happy with minimal effort required. (And they won't even have to wait for the upload to fail.)


As an aside, checking $_SERVER['CONTENT_LENGTH'] vs the size of the post and file data might help detect if something failed. I think it when there is an error it will be non zero, while the $_POST and $_FILES would both be empty.

Monday, October 24, 2022

You couold read this example

which basically does something like this:

$target_dir = "uploads/";
$target_dir = $target_dir . basename( $_FILES["uploadFile"]["name"]);

if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
    echo "The file ". basename( $_FILES["uploadFile"]["name"]). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";

The key is on the $_FILES global array.

To check if there were an error before appliying that example, you could use this example:

if ($_FILES['file']['uploadFile'] === UPLOAD_ERR_OK) { 
* Do the upload process mentioned above
} else { 
* There were an error
Friday, December 2, 2022

If you want to upload a file you should begin with POST /file/to/somewhere.php not GET.

If you want to see the protocol, you could either read up on HTTP specs or even better, install wireshark and do the upload with a browser. Then you can see in wireshark which messages are sent by the browser and just replicate these with your program.

IIRC the protocol should look like this:

POST /to/somewhere.php HTTP/1.1
Content-Type: multipart/form-data;boundary=fdhskjfhldjkshfdksl----

Content-Disposition: name=data;filename=foo.jpg
Content-Type: image/jpg

<binary data here>

I'm typing this from my head so you really should watch the browser do it, but that's the general idea of how post works.

Friday, August 26, 2022

Use NIO to read the file into a gigantic ByteBuffer, and then create a stream class that reads the ByteBuffer. There are several such floating around in open sources.

Saturday, October 29, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :