/ Published in: PHP
This is a function to retrieve the mime-type of a file by checking the header response with curl. It accepts the file-path as a parameter & it also has a fallback for empty returns.
Expand |
Embed | Plain Text
function file_mime($_path) { $ch = curl_init($_path); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); $content_info = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); curl_close($ch); $mime = $content_parts[0]; $get_info = new finfo; $mime = $finfo->file($_path, FILEINFO_MIME); return $mime; } else { $mime = 'application/octet-stream'; return $mime;} }
You need to login to post a comment.
