Jump to content

Validation on image file type not working


bugzy

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:

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.