Reputation: 9476
I have tried both the options:
mime_content_type function
echo mime_content_type($img_path);
finfo function
$finfo = finfo_open(FILEINFO_MIME_TYPE);
echo finfo_file($finfo, $img_path);
finfo_close($finfo);
But I am getting error for both the cases
"Warning: finfo_file(): Failed identify data 0:no magic files loaded"
I am not getting what is the issue in this?
Upvotes: 3
Views: 10708
Reputation: 91
For people wondering in the future, the original poster probably had an external URL set as the path - both the "mime_content_type" & "finfo" functions can only be ran on local paths and not external URLS.
Example:
// Local file path
echo mime_content_type("image.gif");
Will return: image/gif
// External file path
echo mime_content_type("http://localhost/image.gif");
Will return "Warning: mime_content_type(): Failed identify data 0:no magic files loaded"
Fallback versions and more information on usage of these functions can be found in the manual on PHP.net: mime_content_type: http://php.net/manual/en/function.mime-content-type.php
finfo functions: http://php.net/manual/en/book.fileinfo.php
Upvotes: 8
Reputation: 838
looks like $img_path is not containing any file or wrong file path.
Upvotes: 1