Rev 130 Rev 139
Line 1... Line 1...
1 <?php 1 <?php
2 // +----------------------------------------------------------------------+ 2 // +----------------------------------------------------------------------+
3 // | PHP Version 4 | 3 // | PHP Version 4 |
4 // +----------------------------------------------------------------------+ 4 // +----------------------------------------------------------------------+
5 // | Copyright (c) 1997-2004 The PHP Group | 5 // | Copyright (c) 1997-2004 The PHP Group |
6 // +----------------------------------------------------------------------+ 6 // +----------------------------------------------------------------------+
7 // | This source file is subject to version 3.0 of the PHP license, | 7 // | This source file is subject to version 3.0 of the PHP license, |
8 // | that is bundled with this package in the file LICENSE, and is | 8 // | that is bundled with this package in the file LICENSE, and is |
9 // | available at through the world-wide-web at | 9 // | available at through the world-wide-web at |
10 // | http://www.php.net/license/3_0.txt. | 10 // | http://www.php.net/license/3_0.txt. |
11 // | If you did not receive a copy of the PHP license and are unable to | 11 // | If you did not receive a copy of the PHP license and are unable to |
12 // | obtain it through the world-wide-web, please send a note to | 12 // | obtain it through the world-wide-web, please send a note to |
13 // | license@php.net so we can mail you a copy immediately. | 13 // | license@php.net so we can mail you a copy immediately. |
14 // +----------------------------------------------------------------------+ 14 // +----------------------------------------------------------------------+
15 // | Authors: Ian Eure <ieure@php.net> | 15 // | Authors: Ian Eure <ieure@php.net> |
16 // +----------------------------------------------------------------------+ 16 // +----------------------------------------------------------------------+
17 // 17 //
18 // $Id: mime_content_type.php,v 1.3 2005/12/07 21:08:57 aidan Exp $ 18 // $Id: mime_content_type.php,v 1.3 2005/12/07 21:08:57 aidan Exp $
19   19  
20   20  
21 /** 21 /**
22 * Replace mime_content_type() 22 * Replace mime_content_type()
23 * 23 *
24 * You will need the `file` command installed and present in your $PATH. If 24 * You will need the `file` command installed and present in your $PATH. If
25 * `file` is not available, the type 'application/octet-stream' is returned 25 * `file` is not available, the type 'application/octet-stream' is returned
26 * for all files. 26 * for all files.
27 * 27 *
28 * @category PHP 28 * @category PHP
29 * @package PHP_Compat 29 * @package PHP_Compat
30 * @link http://php.net/function.mime_content_type 30 * @link http://php.net/function.mime_content_type
31 * @version $Revision: 1.3 $ 31 * @version $Revision: 1.3 $
32 * @author Ian Eure <ieure@php.net> 32 * @author Ian Eure <ieure@php.net>
33 * @since PHP 4.3.0 33 * @since PHP 4.3.0
34 * @require PHP 4.0.3 (escapeshellarg) 34 * @require PHP 4.0.3 (escapeshellarg)
35 */ 35 */
36 if (!function_exists('mime_content_type')) { 36 if (!function_exists('mime_content_type')) {
37 function mime_content_type($filename) 37 function mime_content_type($filename)
38 { 38 {
39 // Sanity check 39 // Sanity check
40 if (!file_exists($filename)) { 40 if (!file_exists($filename)) {
41 return false; 41 return false;
42 } 42 }
43   43  
44 $filename = escapeshellarg($filename); 44 $filename = escapeshellarg($filename);
45 $out = `file -iL $filename 2>/dev/null`; 45 $out = `file -iL $filename 2>/dev/null`;
46 if (empty($out)) { 46 if (empty($out)) {
47 return 'application/octet-stream'; 47 return 'application/octet-stream';
48 } 48 }
49   49  
50 // Strip off filename 50 // Strip off filename
51 $t = substr($out, strpos($out, ':') + 2); 51 $t = substr($out, strpos($out, ':') + 2);
52   52  
53 if (strpos($t, ';') !== false) { 53 if (strpos($t, ';') !== false) {
54 // Strip MIME parameters 54 // Strip MIME parameters
55 $t = substr($t, 0, strpos($t, ';')); 55 $t = substr($t, 0, strpos($t, ';'));
56 } 56 }
57   57  
58 // Strip any remaining whitespace 58 // Strip any remaining whitespace
59 return trim($t); 59 return trim($t);
60 } 60 }
61 } 61 }
62   62  
63 ?> 63 ?>
64 64