Apache/PHP: $_FILES Array mysteriously empty

Frustrating moment of the day:

A file upload form that’s been working for a long time, suddenly fails. No file uploads work on the entire apache installation. Checking the drive space in the /tmp folder, even though 85MB are left, freeing up space reveals that if there isn’t a lot of free space left for /tmp, the $_FILES array just goes empty without further explanation. No useful error messages, or anything.

Freeing up space for /tmp solves the problem effectively.

Update: Since so many commenters have posted other problems that cause similar effects, here is a quick summary of potential issues that you should check:

  1. Check php.ini for file_uploads = On, post_max_size, and upload_max_file_size. Make sure you’re editing the correct php.ini – use phpinfo() to verify your settings. Make sure you don’t mispell the directives as 8MB instead of the expected 8M!
  2. Make sure your FORM tag has the enctype=”multipart/form-data” attribute. No other tag will work, it has to be your FORM tag. Double check that multipart/form-data is surrounded by STRAIGHT QUOTES, not smart quotes pasted in from Word OR from a website blog (WordPress converts straight quotes to angle quotes!). If you have multiple forms on the page, make sure they both have this attribute. Type them in manually, or try straight single quotes typed in manually.
  3. Do not use javascript to disable your form file input field on form submission!
  4. Make sure your directory has read+write permissions set for the tmp and upload directories.
  5. Make sure your FORM tag has method=”POST”. GET requests do not support multipart/form-data uploads.
  6. Make sure your file destination and tmp/upload directories do not have spaces in them.
  7. Make sure all FORMs on your page have /FORM close tags.
  8. Make sure your file input tag has a NAME attribute. An ID attribute is NOT sufficient! ID attributes are for use in the DOM, not for POST payloads.

118 thoughts on “Apache/PHP: $_FILES Array mysteriously empty

  1. My problem had a solution not posted in here. My host had disabled ‘file_uploads’ by default due to abuse by hackers. To fix it I had to create a blank php.ini file, and place it in the following;

    fileuploads = On uploadmaxfilesize = 10M postmax_size = 10M

    I then uploaded it to the directory of the upload script. Hope this helps, fellow googlers!

  2. My previous comment should have had new lines and underscores for the php.ini file example..

  3. When I remove the enctype, the action=”whatever.php” gets called and the $_FILES array is empty. This makes sense to me. However, when I add the enctype back in (tried single, double quotes) it redirects the page to whatever.php but says that the webpage cannot be displayed. Everything that was talked about in this post had been checked. Also the images I am trying to test with are very small, probably less than 3 kb.

    Any thoughts?

  4. Hi pals, I test all your possiblities , but no solution yet. I am using XAMPP in Windows XP . Any solution let me know

    Thanks Anes

  5. The last part of suggestion #2 helped me out. I had another form on the page that didn’t have enctype set (and was not being used to upload files), which was preventing Chrome (v21 on OS X 10.7) from sending the file to the server.

    I added enctype to the other FORM as you suggested and… voila!


  6. I recommend that you go to the PHP website and look at their list of error codes for PHP file uploads if none of the options help. We were running into a case where the temp file location was not specified and it was not falling back to the system temp file location as it should have done.

  7. I was having the same issue, here’s what worked for me:

    1 – Adding the enctype=”multipart/form-data” attribute. 2 – Changing some SELinux config on the specific upload folder. (Ref: chcon command)

    I’m using Fedora 17/Apache 2.2.22.

    Thanks a lot for your post!

  8. For me, the problem was with the file. I have a .php file and this needs a .html file. A saved the form in a .html and I included it in the .php file. Now it works! =)

Comments are closed.