Problem
WampServer 2 is installed on my Windows 7 machine. Apache 2.2.11 and PHP 5.2.11 are the versions I’m using. When I try to upload a file via a form, it appears to work, but the $_FILES array in PHP is empty. The c:wamptmp folder contains no files. I’ve set up php.ini to allow file uploads and other things. The current user has read/write access to the tmp folder. I’m stumped.
HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form enctype="multipart/form-data" action="vanilla-upload.php" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
PHP:
<?php
echo 'file count=', count($_FILES),"\n";
var_dump($_FILES);
echo "\n";
?>
Asked by elmonty
Solution #1
Here’s a list of things to look for while uploading files with PHP:
https://web.archive.org/web/20050426084124/http://getluky.net/2004/10/04/apachephp- files-array-mysteriously-empty/
Answered by shamittomar
Solution #2
In terms of HTML, you appear to have done everything correctly. You already have the enctype=”multipart/form-data” attribute, which is critical for the form’s success.
In terms of your php.ini configuration, it’s possible that many php.ini files exist on your system. Make certain you’re editing the right one. I understand you mentioned you changed your php.ini file to allow file uploads, but did you also set upload max filesize and post max size to be larger than the file you’re trying to upload? As a result, you must:
file_uploads = On; sounds like you already did this
post_max_size = 8M; change this higher if needed
upload_max_filesize = 8M; change this higher if needed
Does your “c:wamptmp” directory have both read and write permissions? Are you sure you restarted Apache after making the php.ini changes?
Answered by Brian
Solution #3
It is critical to include the enctype=”multipart/form-data” attribute in your form, for example.
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
Answered by meda
Solution #4
Thank you all for your varied and informative responses. All of these are quite beneficial. The answer turned out to be somewhat unusual. PHP 5.2.11 apparently doesn’t like the following:
post_max_size = 2G
or
post_max_size = 2048M
The upload works if I modify it to 2047M.
Answered by elmonty
Solution #5
I’m having the same issue and have been looking for 2 hours. It’s quite simple to verify our server configuration first.
Example:
echo $upload_max_size = ini_get('upload_max_filesize');
echo $post_max_size=ini_get('post_max_size');
Any file size is:20mb, although our upload max size is greater than 20mb, however the array is empty. Our post max size should be bigger than upload max filesize, according to the answer.
post_max_size = 750M
upload_max_filesize = 750M
Answered by shashik493
Post is based on https://stackoverflow.com/questions/3586919/why-would-files-be-empty-when-uploading-files-to-php