Originally posted by barand
I think this might do it for jpg. png or gif
$fileType = array('jpg', 'gif', 'png');
if (!isset($_FILES['attachemnt'])) {}
if (is_uploaded_file($_FILES['attachemnt']['tmp_name'])) {
if ($_FILES['attachemnt']['size']>$attachmentMax) { echo "The file is too big<br>\n"; exit; }
$fname = $_FILES['attachemnt']['name'];
list ($name,$ext)= explode(".", $fname);
if (array_search($ext,$fileType) !== false) {
$res = copy($_FILES['attachemnt']['tmp_name'], $path . $fname);
}
else {echo "Wrong file type<br>\n"; exit; }
}
hth [/B]
Using this code isn't what I really suggest! You are only checking the extension, what if someone just changed the extension, huh? Well, you can use getimagesize() and find out whether it's an image or not, what type it is (swf, jpg, gif,bmp,png,...), whether it's CMYK or not and lots of other things!
About working with the $_FILES array, why don't you put your element in another variable that you only work with a one dim array?