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 PHP, the $_FILES
array is empty. There is no file in the c:\wamp\tmp
folder. I have configured php.ini
to allow file uploads and such. The tmp
folder has read/write privileges for the current user. 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";
?>
If you are using JQuery Mobile
Using a multipart form with a file input is not supported by Ajax. In this case you should decorate the parent form with data-ajax="false" to ensure the form is submitted properly to the server.
I was struggling with the same problem and testing everything, not getting error reporting and nothing seemed to be wrong. I had error_reporting(E_ALL) But suddenly I realized that I had not checked the apache log and voilà! There was a syntax error on the script...! (a missing "}" )
So, even though this is something evident to be checked, it can be forgotten... In my case (linux) it is at:
It is important to add
enctype="multipart/form-data"
to your form, exampleI was empty
$_FILES
because after<form enctype="multipart/form-data" method="post">
i placedInitial code was like
I decided to modify and
So conclusion is that after
<form enctype="multipart/form-data" method="post">
must be<input name, type, id
and must not be<div>
or some other tagsIn my situation correct code was
Check your php.ini for enable_post_data_reading=On , because:
In http://php.net/manual/en/ini.core.php#ini.enable-post-data-reading
If your main script is
http://Some_long_URL/index.php
be carefull to specify the full URL (with explicitindex.php
and not onlyhttp://Some_long_URL
) in theaction
field. Surprisingly, if not, the right script is executed, but with en empty $_FILES !