Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

In file_is_text(): mime_content_type is deprecated and not necessarily available

#15

The mime_content_type function maybe unavailable; It is also deprecated. So we should use Fileinfo instead. If Fileinfo isn't available, we can provide an alternative with the mime_type() Limonade internal function:

    preg_match("/\.([^\.]*?)$/", $filename, $m);
    if($mime = mime_type($m[1])) return substr($mime,0,5) == "text/";

Reported by Fabrice Luraine · July 23rd, 2009 @ 12:12 PM

State: resolved
Assigned to: Fabrice Luraine Fabrice Luraine

Activity

  1. Fabrice Luraine
    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/";
    

    July 23rd, 2009 @ 12:15 PM

  2. Fabrice Luraine
    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 if mime_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;
    }
    

    July 23rd, 2009 @ 12:28 PM

  3. Fabrice Luraine
    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...

    July 31st, 2009 @ 06:44 PM

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.