Project

General

Profile

« Previous | Next » 

Revision 1118

Added by Matthias almost 15 years ago

Replaced function mime_content_type as the old one causes shell_exec warnings on some servers (Thanks to Aldus)

View differences:

functions.php
476 476

  
477 477
// Function for working out a file mime type (if the in-built PHP one is not enabled)
478 478
if(!function_exists('mime_content_type')) {
479
   function mime_content_type($file) {
480
       $file = escapeshellarg($file);
481
       return trim(`file -bi $file`);
482
   }
479
    function mime_content_type($filename) {
480

  
481
    $mime_types = array(
482
            'txt'	=> 'text/plain',
483
            'htm'	=> 'text/html',
484
            'html'	=> 'text/html',
485
            'php'	=> 'text/html',
486
            'css'	=> 'text/css',
487
            'js'	=> 'application/javascript',
488
            'json'	=> 'application/json',
489
            'xml'	=> 'application/xml',
490
            'swf'	=> 'application/x-shockwave-flash',
491
            'flv'	=> 'video/x-flv',
492

  
493
            // images
494
            'png'	=> 'image/png',
495
            'jpe'	=> 'image/jpeg',
496
            'jpeg'	=> 'image/jpeg',
497
            'jpg'	=> 'image/jpeg',
498
            'gif'	=> 'image/gif',
499
            'bmp'	=> 'image/bmp',
500
            'ico'	=> 'image/vnd.microsoft.icon',
501
            'tiff'	=> 'image/tiff',
502
            'tif'	=> 'image/tiff',
503
            'svg'	=> 'image/svg+xml',
504
            'svgz'	=> 'image/svg+xml',
505

  
506
            // archives
507
            'zip'	=> 'application/zip',
508
            'rar'	=> 'application/x-rar-compressed',
509
            'exe'	=> 'application/x-msdownload',
510
            'msi'	=> 'application/x-msdownload',
511
            'cab'	=> 'application/vnd.ms-cab-compressed',
512

  
513
            // audio/video
514
            'mp3'	=> 'audio/mpeg',
515
            'mp4'	=> 'audio/mpeg',
516
            'qt'	=> 'video/quicktime',
517
            'mov'	=> 'video/quicktime',
518

  
519
            // adobe
520
            'pdf'	=> 'application/pdf',
521
            'psd'	=> 'image/vnd.adobe.photoshop',
522
            'ai'	=> 'application/postscript',
523
            'eps'	=> 'application/postscript',
524
            'ps'	=> 'application/postscript',
525

  
526
            // ms office
527
            'doc'	=> 'application/msword',
528
            'rtf'	=> 'application/rtf',
529
            'xls'	=> 'application/vnd.ms-excel',
530
            'ppt'	=> 'application/vnd.ms-powerpoint',
531

  
532
            // open office
533
            'odt'	=> 'application/vnd.oasis.opendocument.text',
534
            'ods'	=> 'application/vnd.oasis.opendocument.spreadsheet',
535
        );
536

  
537
        $temp = explode('.',$filename);
538
        $ext = strtolower(array_pop($temp));
539

  
540
        if (array_key_exists($ext, $mime_types)) {
541
            return $mime_types[$ext];
542
        }
543
        elseif (function_exists('finfo_open')) {
544
            $finfo = finfo_open(FILEINFO_MIME);
545
            $mimetype = finfo_file($finfo, $filename);
546
            finfo_close($finfo);
547
            return $mimetype;
548
        }
549
        else {
550
            return 'application/octet-stream';
551
        }
552
    }
483 553
}
484 554

  
485 555
// Generate a thumbnail from an image

Also available in: Unified diff