| 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 | | } |
|---|
| | 413 | function bb_attachments_mime_type($f) { |
|---|
| | 414 | $disabled=strtolower(ini_get('disable_functions')); $mime=""; |
|---|
| | 415 | |
|---|
| | 416 | if (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 | } |
|---|
| | 419 | elseif (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 | } |
|---|
| | 422 | elseif (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 | } |
|---|
| | 425 | if ((!$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 | } |
|---|
| | 429 | return substr($mime,0,strpos($mime.";",";")); |
|---|