1

I'm currently working with file uploads and trying different ways to get larger files to my server.

However I've found this answer and dont understand why this is ignoring the post_max_size/upload_max_filesize of the php.ini.

I'm using the following code for testing, which work but I don't understand why the php.ini seems to be ignored.

Javascript part:

var reader = new FileReader();
reader.readAsArrayBuffer(file); // alternatively you can use readAsDataURL

reader.onloadend = function (evt)
{
    // create XHR instance
    xhr = new XMLHttpRequest();

    // send the file through POST
    xhr.open("POST", 'upload.php', true);

    // make sure we have the sendAsBinary method on all browsers
    XMLHttpRequest.prototype.mySendAsBinary = function (text)
    {
        var data = text;

        if(typeof window.Blob == "function")
        {
            var blob = new Blob([data]);
        } 
        else
        {
            var bb = new (window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder)();
            bb.append(data);
            var blob = bb.getBlob();
        }
        this.send(blob);
    }

    // start sending
    xhr.mySendAsBinary(evt.target.result);
};

PHP part:

// read contents from the input stream
$inputHandler = fopen('php://input', "r");
$buffer = fgets($inputHandler, 4096);

// do some stuff and keep reading with $buffer = fgets($inputHandler, 4096);

So my question here is: Why does my upload.php receive files if they're several GB in size even if post_max_size is limited to 8MB and upload_max_filesize is limited to 2MB?

Community
  • 1
  • 1
Nitro.de
  • 821
  • 10
  • 27

1 Answers1

0

I believe post_max_size relates to the maximum amount of POST data allowed, whereas upload_max_filesize is the maximum allowed size for uploaded files? Try checking your php.ini file to see what the values are there.

David Wilkinson
  • 5,060
  • 1
  • 18
  • 32
  • upload_max_filesize = 2M and post_max_size = 8M – Nitro.de Dec 17 '15 at 15:28
  • @Nitro.de you wrote in question that `post_max_size is limited to 2MB?` so maybe decide what's your post_max_size value – Robert Dec 17 '15 at 15:30
  • @robert fixed just took the wrong line of php.ini^^ – Nitro.de Dec 17 '15 at 15:32
  • @Nitro.de - if you're running Apache, I know there's a way of setting both `upload_max_filesize` and `post_max_size` within .htaccess files? Might be worth some research? Unfortunately, my knowledge of Apache is limited as I'm an Nginx man... – David Wilkinson Dec 17 '15 at 15:32
  • @samuidavid i'll take a look at it.. btw i'm running Apache yes – Nitro.de Dec 17 '15 at 15:33
  • @samuidavid well nothing there – Nitro.de Dec 17 '15 at 15:39
  • Hmmmm, sorry to repeat but do you have more than one htaccess file? If you have multiple files, there could be a rogue statement in one of those. – David Wilkinson Dec 17 '15 at 15:53
  • This is a long-shot, but make sure you've been looking at the right config / ini file by typing in `php -i` into the command line / terminal and checking where your config file is located next to "Configuration File". Just make sure you're looking at the right ini file in the right location :-) I've made that mistake before. – David Wilkinson Dec 17 '15 at 16:07
  • I've checken everything but I can't find any other size limitation. However i've googled around a bit and found several sites which say that this ignores the limitations but couldn't find out why -.- – Nitro.de Dec 19 '15 at 10:25