Jump to content

Recommended Posts

I'm validating if a user chose an image file or not but it seemed like it's not working..

 

I have this form:

 

<form method="post" name="add_item" enctype="multipart/form-data" action="add_item.php">

 

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

 

<input name="uploaded_image" type="file" />

 

<input type="submit" value="Add Item" name="submit" size="30" />

 

</form>

 

 

 

php code:

 

 

<?php

if(isset($_FILES['uploaded_image']))
{	
	//User has chose a file
}
else
{
	//Uder didn't choose a file
}


?>

 

 

It keeps on telling me that I have chose a file even if I didn't. I also tried using "empty" but it didn't work...

 

anyone?

Add this right after the opening php tag and I'm sure you'll see why that's happening.

 

echo '$_FILES array:<pre>';
print_r($_FILES);
echo '</pre>';

 

If I'm not choosing a file this is what I'm getting

 

 

<?php
$_FILES array:

Array
(
    [uploaded_image] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

)
?>

 

 

if I chose a file here's what I'm getting

 

<?php

$_FILES array:

Array
(
    [uploaded_image] => Array
        (
            [name] => matzhee_logo.gif
            [type] => image/gif
            [tmp_name] => C:\wamp\tmp\php73B9.tmp
            [error] => 0
            [size] => 1189
        )

)


?>

 

 

 

:confused:

Exactly. Do you see why checking to see if $_FILES['upoaded_image'] isset() isn't going to work?

 

Here you go

<?php

if($_FILES['uploaded_image']['error'] == 4)
{	
	//User didn't choose a file
}
else
{
	//User choose a file
}

?>

 

 

Thanks Pikachu2000  8)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.