In file_is_text(): mime_content_type is deprecated and not necessarily available
-
Fabrice Luraine
Instead of the above regexp, we can use file_extension() Limoande function
$ext = strtolower(file_extension($filename)); if($mime = mime_type($ext)) return substr($mime,0,5) == "text/"; -
Fabrice Luraine
The
mime_content_type()compatibility alternate function must be rewritten to apply above changes. And it should be renamed to avoid confusion and be used even ifmime_content_type()native function exists.So, replace:
if(!function_exists('mime_content_type')) { /** * Detect MIME Content-type for a file * * @param string $filename Path to the tested file. * @return string */ function mime_content_type($filename) { $ext = strtolower(array_pop(explode('.', $filename))); if($mime = mime_type($ext)) return $mime; elseif (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME); $mime = finfo_file($finfo, $filename); finfo_close($finfo); return $mime; } else return 'application/octet-stream'; } }with something like this:
/** * Detect MIME Content-type for a file * * @param string $filename Path to the tested file. * @return string */ function file_mime_content_type($filename) { $ext = file_extension($filename); /* strtolower isn't necessary */ if($mime = mime_type($ext)) return $mime; elseif (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME); $mime = finfo_file($finfo, $filename); finfo_close($finfo); return $mime; } else return 'application/octet-stream'; }And use it in
file_is_text():function file_is_text($filename) { if($mime = file_mime_content_type($filename)) return substr($mime,0,5) == "text/"; return null; } -
Fabrice Luraine
- State changed from new to resolved
(from [c6714c0f2717b0aa828060b366c9117e66efbfb1]) Fix bug in file_is_text, removes mime_content_type compatibility function and add file_mime_content_type() [#15 In file_is_text(): mime_content_type is deprecated and not necessarily available state:resolved] http://github.com/sofadesign/limonade/commit/c6714c0f2717b0aa828060...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.