Marco
Marco

Reputation: 2737

How to check if the uploaded file is a supported file

i'm uploading a tif file, but i always get the echo 'The uploaded file type is not supported'. Why? How do i check if file is supported according to my array of supported files

//image types supported
$types = array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_TIFF);

list($width, $height, $type) = getimagesize($_FILES[$name]['tmp_name']);
$ext = image_type_to_extension($type); // get the extension

if (!isset($types[$type])) {
   echo = 'The uploaded file type is not supported';
} else
   echo = 'All good!';
}

Upvotes: 2

Views: 265

Answers (2)

Musa
Musa

Reputation: 97707

You're checking if $types has a key $type rather than a value $type. Instead use in_array.
Also form http://www.php.net/manual/en/function.image-type-to-mime-type.php, there is no IMAGETYPE_TIFF but instead IMAGETYPE_TIFF_II and IMAGETYPE_TIFF_MM

$types = array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM);
...
if (in_arry($type,$types)) {

Upvotes: 2

René Höhle
René Höhle

Reputation: 27305

I think your TYPE is not correct try the following types.

IMAGETYPE_TIFF_II     => 'tiff',        ###  7 = TIFF     (intel byte order)
IMAGETYPE_TIFF_MM     => 'tiff',        ###  8 = TIFF     (motorola byte order)

Upvotes: 2

Related Questions