Thursday, September 24, 2009

PHP: empty $_FILES array

This experience might be really time consuming. You get a simple form with a simple input field of type="file" and on the server side you get nothing. The $_FILES array is empty as a whistle.

You can get really frustrated after checking whether file_uploads = 1, upload_temp_dir is accessible and upload_max_filesize is big enough and everything seems fine.

In this case it's worth checking if the troublemaker is not... the form itself. If there is no enctype="multipart/form-data" in the form tag, you may want to try it. Here is an example of working file upload:

<form name="form" action="index.php" method="post" enctype="multipart/form-data">
<fieldset>
<label>Upload file</label>
<input type="file" name="userfile" />
</fieldset>
<fieldset>
<input type="submit" value="OK" />
</fieldset>
$lt;/form>


I have found a Nice thread about the above issue which you might be interested in as well.

No comments:

Post a Comment