I have WampServer 2 installed on my Windows 7 computer. I\'m using Apache 2.2.11 and PHP 5.2.11. When I attempt to upload any file from a form, it seems to upload, but in PH
Here's a check-list for file uploading in PHP:
Check php.ini for:
file_uploads = On
post_max_size = 100M
upload_max_filesize = 100M
.htaccess
or .user.ini
if you are on shared hosting and don't have access to php.ini
.phpinfo()
function to verify your
settings are actually being applied. 100M
not 100MB
.Make sure your tag has the
enctype="multipart/form-data"
attribute. No other tag will work, it has to be your FORM tag. Double check that it is spelled correctly. 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.
Make sure you do not have two input file fields with the same name
attribute. If you need to support multiple, put square brackets at the end of the name:
Make sure your tmp and upload directories have the correct read+write permissions set. The temporary upload folder is specified in PHP settings as upload_tmp_dir
.
Make sure your file destination and tmp/upload directories do not have spaces in them.
Make sure all 's on your page have
close tags.
Make sure your FORM tag has method="POST"
. GET requests do not support multipart/form-data uploads.
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.
Make sure you are not using Javascript to disable your field on submission
Make sure you're not nesting forms like
Check your HTML structure for invalid/overlapping tags like
Also make sure that the file you are uploading does not have any non-alphanumeric characters in it.
Once, I just spent hours trying to figure out why this was happening to me all of a sudden. It turned out that I had modified some of the PHP settings in .htaccess
, and one of them (not sure which yet) was causing the upload to fail and $_FILES
to be empty.
You could potentially try avoiding underscores (_
) in the name=""
attribute of the tag
Try uploading very small files to narrow down whether it's a file-size issue.
Check your available disk space. Although very rare, it is mentioned in this PHP Manual page comment:
If the $_FILES array suddenly goes mysteriously empty, even though your form seems correct, you should check the disk space available for your temporary folder partition. In my installation, all file uploads failed without warning. After much gnashing of teeth, I tried freeing up additional space, after which file uploads suddenly worked again.
Be sure that you're not submitting the form through an AJAX POST request instead of a normal POST request that causes a page to reload. I went through each and every point in the list above, and finally found out that the reason due to which my $_FILES variable was empty was that I was submitting the form using an AJAX POST request. I know that there are methods to upload files using ajax too, but this could be a valid reason why your $_FILES array is empty.
Source for some of these points:
http://getluky.net/2004/10/04/apachephp-_files-array-mysteriously-empty/