Ok, I'm confused. I am trying to learn how to upload an image file in PHP.
<form name="add_form" action="submit.php" method="post" enctype="multipart/form-data">
<input type="file" name="image">
<button type="submit">Submit</button>
</form>
in the submit.php file:
print_r($_FILES);
if(empty($_FILES['file']['name'])){
echo "empty";
}else{
echo "not empty";
}
print_r($_FILES); shows me this:
Array ( [image] => Array ( [name] => van Gogh - GalleryPlayer.jpg [type] => image/jpeg [tmp_name] => /tmp/phpbYjG7m [error] => 0 [size] => 1437795 ) )
But when I run if/else using (empty($_FILES['file']['name'])) it always echos "empty". How can it be empty if it is in the print_r($_FILES) array?
My ultimate goal here is to check if the user has uploaded an image file (it's part of a larger form). If they do, use it. If not, use a default image. So i'm just trying to test for the existence of the form field. Make sense?
Thanks for any insight you may be able to provide.
Cheers!