Richard Garside Richard Garside - 6 months ago 46
PHP Question

No error when uploading a really big file in PHP?

I have a PHP form for uploading files and it works fine and displays an error message if something went wrong. This is all good.

The problem is when I test with a really big file, it just refreshes the page as if I hadn't sent a file at all, and none of the $_POST variables from the form are even sent to the server.

I want to display an error to the user, letting them know that the file is too big. However, I can't do this.

Does anyone know what is happening?


Check your PHP ini file, which governs how large a file PHP will allow to be uploaded. These variables are important:

  • max upload filesize (upload_max_filesize)
  • max post data size (post_max_size)
  • memory limit (memory_limit)

Any uploads outside these bounds will be ignored or errored-out, depending on your settings.

This section in the docs has the best summary:

EDIT: Also note that most browsers won't send uploads over 2GB in size. This link is outdated, but gives an idea: Anyone have a better source of info on this?

There are also limits that can be imposed by the server, such as Apache:

To truly see what's going on, you should probably check your webserver logs, check the browser upload limit (if you're using firefox), and try seeing if print_r($_FILES) generates any useful error numbers. If all else fails, try the net traffic monitor in firebug. The key is to determine if the request is even going to the server, and if it is what the request (including headers) looks like. Once you've gotten that far in the chain, then you can go back and see how PHP is handling the upload.