JM at Work
JM at Work

Reputation: 2437

Why is PHP $_FILES always null

I have HTML like

<form action="send.php" method="post" enctype="multipart/form-data">
    <div>
        <label for="subject">Subject</label>
        <input type="text" name="subject" />
    </div>
    <div>
        <label for="image">Image</label>
        <input type="file" name="image" />
    </div>
    <input type="submit" value="Send" />
</form>

I keep getting null for $_FILES why is that?

Upvotes: 4

Views: 19631

Answers (5)

Murolack
Murolack

Reputation: 2167

I got the same problem and none of theme was my error. Check in your .htaccess file, if you got one, if "MultiViews" are enabled. I had to disable them.

Upvotes: 0

user2284144
user2284144

Reputation: 93

In the form section make sure you have this code: enctype="multipart/form-data"

Upvotes: 10

Jumpey
Jumpey

Reputation: 156

file_uploads might be off in php.ini. Try this script:

<?php
echo 'file_uploads: '. ini_get('file_uploads'). '<br />';
echo 'upload_tmp_dir: '. ini_get('upload_tmp_dir'). '<br />';
echo 'upload_max_filesize: '. ini_get('upload_max_filesize'). '<br />';
echo 'max_file_uploads: '. ini_get('max_file_uploads'). '<br />';
?>

Upvotes: 0

Sujeet
Sujeet

Reputation: 1800

<?php print_r($_FILES);?>

<form action="" method="post" enctype="multipart/form-data">
    <div>
        <label for="subject">Subject</label>
        <input type="text" name="subject" />
    </div>
    <div>
        <label for="image">Image</label>
        <input type="file" name="image" />
    </div>
    <input type="submit" value="Send" />
</form>

Check the code above:

it should produce the following output:

Array
(
    [image] => Array
        (
            [name] => ezwebin_userguide.pdf
            [type] => application/pdf
            [tmp_name] => C:\Windows\Temp\php1485.tmp
            [error] => 0
            [size] => 1073054
        )

)

Upvotes: 9

Zakaria
Zakaria

Reputation: 15070

Have you tried echoing more specific data? Ex:

echo $_FILES["file"]["error"]

Or

echo $_FILES["file"]["name"]

Regards.

Upvotes: 0

Related Questions