File Restrictions on PHP Upload

I’ve been building this script and i can’t figure out how to restrict all files except JPG, GIF, and PNG

Please help!

[php] <?php
$target = “images/”;
$target = $target . basename( $_FILES[‘uploaded’][‘name’]) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 230000)
{
echo “Your file is too large.
”;
$ok=0;
}

if (!($uploaded_type==“image/gif”))
{
echo “You may only upload GIF files.
”;
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo “Sorry your file was not uploaded”;
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES[‘uploaded’][‘tmp_name’], $target))
{
echo "The file “. basename( $_FILES[‘uploadedfile’][‘name’]). " has been uploaded”;
}
else
{
echo “Sorry, there was a problem uploading your file.”;
}
}
?> [/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service