Asked  7 Months ago    Answers:  5   Viewed   40 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, March 31, 2021
answered 7 Months ago

I would use exec() to run a local hashing function in the shell and return the value back to the php script. Here's an example with md5 but any algo available can be used.

  $results = array();
  $filename = '/full/path/to/file';
  exec("md5sum $filename", $results);

Then parse the result array (the output of the shell command).

In general, I like to avoid doing anything directly in PHP that requires more than 1G of memory, especially if running in php-fpm or as an apache module--sort of time reinforced prejudice. This is definitely my advice when there is a native application that can accomplish the goal and you don't particularly need portablitly cross platform (like run on both linux and windows machines).

Saturday, May 29, 2021
answered 5 Months ago
public void checkinstream(String rid, String filename ) throws IOException
                  URL url=null;
                HttpURLConnection conn = null;
                    DataOutputStream dos = null;
                    DataInputStream inStream = null;
                    String existingFileName= null;

                     existingFileName=    "/mnt/sdcard/"+rid+".doc";
                    int bytesRead, bytesAvailable, bufferSize;
                    byte[] buffer;
                    int maxBufferSize = Integer.MAX_VALUE;
                    String responseFromServer = "";

                 url = new URL("");               

                     //------------------ CLIENT REQUEST
                    FileInputStream fileInputStream = new FileInputStream(new File(existingFileName) );

                     // Open a HTTP connection to the URL
                     conn = (HttpURLConnection) url.openConnection();
                     // Allow Inputs
                     // Allow Outputs
                     // Don't use a cached copy.
                     // Use a post method.
                     conn.setRequestProperty("Connection", "Keep-Alive");
                     conn.setRequestProperty("Content-Type", "application/stream");
                     dos = new DataOutputStream( conn.getOutputStream() );
                  //   dos.writeBytes(twoHyphens + boundary + lineEnd);
                     //dos.writeBytes("Content-Disposition: form-data; name="uploadedfile";filename="" + existingFileName + """ + lineEnd);
                   //  dos.writeBytes(lineEnd);
                     // create a buffer of maximum size
                     bytesAvailable = fileInputStream.available();
                     bufferSize = Math.min(bytesAvailable, maxBufferSize);
                     buffer = new byte[bufferSize];
                     // read file and write it into form...
                     bytesRead =, 0, bufferSize);
                     while (bytesRead > 0)
                      dos.write(buffer, 0, bufferSize);
                      bytesAvailable = fileInputStream.available();
                      bufferSize = Math.min(bytesAvailable, maxBufferSize);
                      bytesRead =, 0, bufferSize);

                     // send multipart form data necesssary after file data...

                     // close streams
                     Log.e("Debug",twoHyphens + boundary + twoHyphens + lineEnd);
                    catch (MalformedURLException ex)
                         Log.e("Debug", "error: " + ex.getMessage(), ex);
                    catch (IOException ioe)
                         Log.e("Debug", "error: " + ioe.getMessage(), ioe);
                    //------------------ read the SERVER RESPONSE
                    try {
                          inStream = new DataInputStream ( conn.getInputStream() );
                          String str;

                          while (( str = inStream.readLine()) != null)
                               Log.e("Debug","Server Response "+str);

                    catch (IOException ioex){
                         Log.e("Debug", "error: " + ioex.getMessage(), ioex);


On the .net end create a wcf method which receives stream. Thanks.

Tuesday, August 10, 2021
answered 2 Months ago

After many hours of experimentation with misleading solutions on the uplodifive forum, this is the solution.

In your HTML anchor tag:

<input id="file_upload" name="file_upload" type="file" multiple="true">
<a style="position: relative; top: 8px;" href="javascript:$('#file_upload').uploadifive('upload')">Upload Files</a>

Change the anchor tag to:

<a style="position: relative; top: 8px;" href="javascript:uploadFiles();">Upload Files</a>

Completely eliminate the formData setting from the initial function call so it then looks something like this:

        'auto'               : false,
        'dnd'                : true,
        'checkScript'        : 'check-exists.php',
        'queueID'            : 'queue',
        'uploadScript'       : 'upload.php',
        'onUploadComplete'   : function(file, data) {console.log(data);}

Than add this function:

   function uploadFiles()
      $('#file_upload').data('uploadifive').settings.formData =
         'timestamp' : '<?php echo $timestamp;?>',
         'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
         'MyNumber'  : $('#MyInputVariable').val()

And whatever other variables you need to add. Your input variables will now post on upload.

Saturday, August 14, 2021
answered 2 Months ago

According to my experience there is no way to upload file over 2Gb in a single request. There is a 2Gb limitation in IIS, and there is no workaround.

In .Net 4.0 and earlier there were also a 2Gb (some people say 4Gb) limitation in ASP.NET, that was fixed in .Net 4.5. However this fix makes a little sense because IIS itself does not support file uploads over 2Gb.

The only way to upload files over 2Gb to IIS-hosted server is to break it into pieces and upload piece by piece. Here are clients that can upload breaking a file into segments:

  1. IT Hit Ajax File Browser
  2. Sample WebDAV Browser

Note that these clients require your server to support PUT with Range header.

Another solution is to create a HttpListener-based server. HttpListener has much less functionality comparing to IIS but it does not have any upload limitations.

Monday, August 23, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :