We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

workaround for disabled PHP fileinfo extension?

Development and Programming

adambeazley's avatar
adambeazley
153 posts
10 years ago
adambeazley's avatar adambeazley

Hello,

So I just updated to EE 2.10.1 and now I just found out that my hosting company cannot enable the Fileinfo PHP extension unless I move up to a virtual private server (too expensive). Is there some code I can use in the MimeType.php to change the finfo_open() function on line 117 so that EE will still function properly?

thanks,

Adam

       
adambeazley's avatar
adambeazley
153 posts
10 years ago
adambeazley's avatar adambeazley

So the offending code in the MimeType.php is the following function:

$finfo = finfo_open(FILEINFO_MIME_TYPE);
  if ($finfo !== FALSE)
  {
   $fres = @finfo_file($finfo, $path);
   if ( ($fres !== FALSE)
    && is_string($fres)
    && (strlen($fres)>0))
   {
    $mime = $fres;
   }

   @finfo_close($finfo);
  }

so what if I were to setup a static function to return the mime type without using the fileinfo that my stupid host has disabled:

Sample code to start with:

private static function get_mime_type($path) {

    $mime_types = array(

        'txt' => 'text/plain',
        'htm' => 'text/html',
        'html' => 'text/html',
        'php' => 'text/html',
        'css' => 'text/css',
        'js' => 'application/javascript',
        'json' => 'application/json',
        'xml' => 'application/xml',
        'swf' => 'application/x-shockwave-flash',
        'flv' => 'video/x-flv',

        // images
        'png' => 'image/png',
        'jpe' => 'image/jpeg',
        'jpeg' => 'image/jpeg',
        'jpg' => 'image/jpeg',
        'gif' => 'image/gif',
        'bmp' => 'image/bmp',
        'ico' => 'image/vnd.microsoft.icon',
        'tiff' => 'image/tiff',
        'tif' => 'image/tiff',
        'svg' => 'image/svg+xml',
        'svgz' => 'image/svg+xml',

        // archives
        'zip' => 'application/zip',
        'rar' => 'application/x-rar-compressed',
        'exe' => 'application/x-msdownload',
        'msi' => 'application/x-msdownload',
        'cab' => 'application/vnd.ms-cab-compressed',

        // audio/video
        'mp3' => 'audio/mpeg',
        'qt' => 'video/quicktime',
        'mov' => 'video/quicktime',

        // adobe
        'pdf' => 'application/pdf',
        'psd' => 'image/vnd.adobe.photoshop',
        'ai' => 'application/postscript',
        'eps' => 'application/postscript',
        'ps' => 'application/postscript',

        // ms office
        'doc' => 'application/msword',
        'rtf' => 'application/rtf',
        'xls' => 'application/vnd.ms-excel',
        'ppt' => 'application/vnd.ms-powerpoint',

        // open office
        'odt' => 'application/vnd.oasis.opendocument.text',
        'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
    );

    $ext = strtolower(array_pop(explode('.',$path)));
    if (array_key_exists($ext, $mime_types)) {
        return $mime_types[$ext];
    }
    elseif (function_exists('finfo_open')) {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $fres = @finfo_file($finfo, $path);
        finfo_close($finfo);
        return $mime;
    }
    else {
        return 'application/octet-stream';
    }
}

Anyone want to help me with this challenge?

       
gptnederlands's avatar
gptnederlands
1 posts
2 years ago
gptnederlands's avatar gptnederlands

Are you ready to immerse yourself in the world of limitless language exploration? Discover the endless possibilities that ChatGPT Nederlands offers, right here on GPTNederlands.nl. Begin your journey towards elevated communication today, and unlock the true potential of language like never before.

ChatGPT Nederlands - Where words become art, conversations become captivating, and linguistic boundaries become a thing of the past. Join us on this incredible linguistic odyssey, and let your voice be heard like never before!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.