Hi, I am looking for the best way to find out the mime type in php for any local file or url. I tried the mime_content_type php function, but since it is deprecated, I am looking for the best solution in php for all file formats.
mime_content_type — Detect MIME Content-type for a file ***(deprecated)***
I already tried below function
echo 'welcome'; if (function_exists('finfo_open')) { echo 'testing'; $finfo = finfo_open(FILEINFO_MIME); $mimetype = finfo_file($finfo, "http://4images.in/wp-content/uploads/2013/12/Siberian-Tiger-Running-Through-Snow-Tom-Brakefield-Getty-Images-200353826-001.jpg"); finfo_close($finfo); echo $mimetype; }
The code does not work for me, I see only welcome for output. I'm not sure I'm doing anything wrong here.
Below code works somehow in my local, but it does not work for URLs.
$file = './apache_pb2.png'; $file_info = new finfo(FILEINFO_MIME); // object oriented approach! $mime_type = $file_info->buffer(file_get_contents($file)); // eg gives "image/jpeg" $mime = explode(';', $mime_type); print $mime[0];
Is there some kind of work that works for both (url and local). What is the best practice for setting the mime type for all content (image, video, file, etc.), except for the mime_content_type function in php.also, it is recommended to use the mime_content_type function in php, is this better in php?
content-type mime-types php amazon-web-services cdn
Hitesh Feb 20 '14 at 11:36 2014-02-20 11:36
source share