2

I have a common problem in PHP : My $_FILES array is empty when files are too big.

php.ini :

max_execution_time = 300000
max_input_time = 600000000
memory_limit = 5100MB
post_max_size = 5000MB
upload_max_filesize = 5000MB

The file :

Trouve.tar : 910Mo

Configuration values are huge but I want to be sure that the script have the time and the memory to do the upload.

So, the authorized size is bigger than the file size, but I have the same error than other people (like problem with uploading the images with php file upload for exemple)

Have I missed some configuration setting ?

Community
  • 1
  • 1
MARTIN Damien
  • 996
  • 2
  • 15
  • 36
  • Seriously, is that 910 megabytes? I didn't look it up, but PHP likely has some builtin hard limits. – mario Jan 17 '11 at 15:20
  • Just to clarify, it works with small files? – Naatan Jan 17 '11 at 15:22
  • @Naatan Yes it works without any problems. – MARTIN Damien Jan 17 '11 at 15:24
  • Single file? Must it be a form request? Else capturing a PUT request might make sense. – mario Jan 17 '11 at 15:28
  • @mario Yes it is a single file from a form request. I didn't know PUT request, I'll try this. – MARTIN Damien Jan 17 '11 at 15:32
  • Using firebug or equivalent to track the http request, does it upload the full 910mb? Have you checked the response headers for any clues as to why its faling? – Naatan Jan 17 '11 at 15:33
  • Caveat: PUT doesn't work via forms. Major browsers support it via AJAX at best. So that's why I put that use case question forward. It's a probable option if you do server to server uploads. – mario Jan 17 '11 at 15:34

4 Answers4

6

The problem is your post_max_size is the same size as upload_max_filesize which will cause the $_FILES array (and $_POST) to be empty. If you up the limit on the post_max_size, the $_FILES array will no longer be empty.

EDIT: Not sure why the negative vote. While it may not apply exactly in this case, it is worth mentioning. This is exactly what php.net says: http://www.php.net/manual/en/ini.core.php#ini.post-max-size.

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty.

Chuck Burgess
  • 11,600
  • 5
  • 41
  • 74
3

Check your upload_limit in your php.ini settings.

In your html form tag, do not forget to put this: enctype="multipart/form-data"

hahaha
  • 468
  • 4
  • 12
  • Thank you hlegius but I cant find "upload_limit" in my php.ini and seems to not exists : http://www.google.fr/search?sourceid=chrome&ie=UTF-8&q=site:php.net+max_execution_time#sclient=psy&hl=fr&safe=off&q=site:php.net+%22upload_limit%22&aq=&aqi=&aql=&oq=&pbx=1&fp=92e401c307f5f81f. My form works with small files (until approximatively 300Mo), so yes "enctype="multipart/form-data"" is set. – MARTIN Damien Jan 21 '11 at 09:38
3

Instead of MB use M

memory_limit = 5100M

post_max_size = 5000M

upload_max_filesize = 5000M
egg
  • 1,736
  • 10
  • 12
1

Check you web server limits in addition to the php.ini configuration.

For example, you'll probably have to increase the LimitRequestBody if you're using Apache or the client_max_body_size if you're using nginx.

When an HTTP request is larger that the limit accepted by the web server, it returns an HTTP response with status: 413 Request Entity Too Large.

scoffey
  • 4,638
  • 1
  • 23
  • 27
  • LimitRequestBody has been set to 0 (no limit) and the result script is shown (no server error for a "too large file"). – MARTIN Damien Jan 21 '11 at 09:40
  • Make sure these settings are OK in the php.ini or the virtual host configuration file: `upload_max_filesize`, `post_max_size`, `max_execution_time` and `max_input_time`. What's the output when debugging: `var_dump($_FILES)` and `var_dump($_REQUEST)`? You may also try activating `LogLevel debug` in Apache to check any problems the server logs when you upload the file. – scoffey Jan 21 '11 at 15:30