Changeset 1020

Show
Ignore:
Timestamp:
04/27/08 22:44:12 (7 months ago)
Author:
_ck_
Message:

0.0.8 more aggressive mime-type checking with fallback

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bb-attachments/trunk/bb-attachments.php

    r1014 r1020  
    66Author: _ck_ 
    77Author URI: http://bbShowcase.org 
    8 Version: 0.0.7 
     8Version: 0.0.8 
    99 
    1010License: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/ 
     
    202202                        $tmp=$_FILES['bb_attachments']['tmp_name'][$key]; 
    203203                        $size=filesize($tmp);    
    204                         $mime=mime_content_type($tmp); $mime=substr($mime,0,strpos($mime.";",";"));                                    
     204                        $mime=bb_attachments_mime_type($tmp);                                  
    205205                        $status=0; $id=0; 
    206206                         
     
    411411} 
    412412 
    413 if ( ! function_exists ( 'mime_content_type' ) ) {      // most newer PHP doesn't have this 
    414  
    415 if (function_exists('finfo_open') && function_exists('finfo_file')) {   // try finfo 
    416  
    417         function mime_content_type( $f )  {$finfo=finfo_open(FILEINFO_MIME); return trim(finfo_file($finfo, $f));} 
    418  
    419 } else {                //  so try shell  ?  - will fail on windows 100% of the time 
    420  
    421         function mime_content_type( $f )  {return trim (@exec ('file -bi ' . escapeshellarg ( $f ) ) ) ;} 
    422 }        
     413function bb_attachments_mime_type($f) { 
     414$disabled=strtolower(ini_get('disable_functions')); $mime=""; 
     415 
     416if (function_exists('mime_content_type') && strpos($disabled,'mime_content_type')===false) {    // many newer PHP doesn't have this 
     417        $mime=mime_content_type($f); 
     418
     419elseif (function_exists('finfo_open') && function_exists('finfo_file') && strpos($disabled,'finfo_open')===false) {     // try finfo 
     420        $finfo=finfo_open(FILEINFO_MIME);  $mime=trim(finfo_file($finfo, $f)); 
     421}  
     422elseif (function_exists('exec') && strpos($disabled,'exec')===false) {  //  so try shell  ?  - will fail on windows 100% of the time? 
     423        $mime=trim(@exec('file -bi '.escapeshellarg($f))); 
     424
     425if ((!$mime || strpos($mime,'file -bi')!==false) && function_exists('getimagesize') && function_exists('image_type_to_mime_type')  && strpos($disabled,'getimagesize')===false) {  
     426        // use image function in worst case senario - won't do text types - must fix ! 
     427        $mime=""; $imgt =@getimagesize($f);  if ($imgt) {$mime=image_type_to_mime_type($imgt[2]);}      // 0=width  1=height 
     428
     429return substr($mime,0,strpos($mime.";",";"));    
    423430} 
    424431