Reputation: 21
Where can I get the four magic files to be included in the C:\xampp\php\extras
folder to get the correct MIME type($finfo = finfo_open(FILEINFO_MIME_TYPE,'C:/xampp/php/extras')
)?
Upvotes: 0
Views: 153
Reputation: 21
Finally i found an answer...The following is the code i have used.
list($width, $height, $image_type) = getimagesize($_FILES["photo"]["tmp_name"]);
$mime_photo = image_type_to_mime_type($image_type);
Description
getimagesize() function can be used to get the width,height,image type etc.
Then i used image_type_to_mime_type() function with parameter as $image_type.This function returns the correct MIME Type.
If you are using ($_FILES["photo"]["type"]== "image/jpeg") to compare the image type and suppose suppose you are changing the extension of a file say 'myprofile.txt' to 'myprofile.jpg' the comparison will be true,it read as 'image/jpeg',but if you are comparing using the MIME type then it will be false.
comparing using content type:
if (($_FILES["photo"]["type"]== "image/jpeg") || ($_FILES["photo"]["type"]== "image/jpg"))
{
echo 'The image is valid and its type is '.$_FILES["photo"]["type"];
}
else {
echo 'The image is invalid and its type is '.$_FILES["photo"]["type"];
}
Comparing using MIME type:
if (($mime_photo== "image/jpeg") || ($mime_photo== "image/jpg"))
{
echo 'The image is valid and its MIME Type is '.$mime_photo;
}
else {
echo 'The image uploaded is invalid and its MIME Type is '.$mime_photo;
}
Upvotes: 1