1 | <?php |
---|
2 | // +----------------------------------------------------------------------+ |
---|
3 | // | PHP Version 4 | |
---|
4 | // +----------------------------------------------------------------------+ |
---|
5 | // | Copyright (c) 1997-2004 The PHP Group | |
---|
6 | // +----------------------------------------------------------------------+ |
---|
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 | |
---|
9 | // | available at through the world-wide-web at | |
---|
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 | |
---|
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. | |
---|
14 | // +----------------------------------------------------------------------+ |
---|
15 | // | Authors: Ian Eure <ieure@php.net> | |
---|
16 | // +----------------------------------------------------------------------+ |
---|
17 | // |
---|
18 | // $Id$ |
---|
19 | |
---|
20 | |
---|
21 | /** |
---|
22 | * Replace mime_content_type() |
---|
23 | * |
---|
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 |
---|
26 | * for all files. |
---|
27 | * |
---|
28 | * @category PHP |
---|
29 | * @package PHP_Compat |
---|
30 | * @link http://php.net/function.mime_content_type |
---|
31 | * @version $Revision: 1.3 $ |
---|
32 | * @author Ian Eure <ieure@php.net> |
---|
33 | * @since PHP 4.3.0 |
---|
34 | * @require PHP 4.0.3 (escapeshellarg) |
---|
35 | */ |
---|
36 | if (!function_exists('mime_content_type')) { |
---|
37 | function mime_content_type($filename) |
---|
38 | { |
---|
39 | // Sanity check |
---|
40 | if (!file_exists($filename)) { |
---|
41 | return false; |
---|
42 | } |
---|
43 | |
---|
44 | $filename = escapeshellarg($filename); |
---|
45 | $out = `file -iL $filename 2>/dev/null`; |
---|
46 | if (empty($out)) { |
---|
47 | return 'application/octet-stream'; |
---|
48 | } |
---|
49 | |
---|
50 | // Strip off filename |
---|
51 | $t = substr($out, strpos($out, ':') + 2); |
---|
52 | |
---|
53 | if (strpos($t, ';') !== false) { |
---|
54 | // Strip MIME parameters |
---|
55 | $t = substr($t, 0, strpos($t, ';')); |
---|
56 | } |
---|
57 | |
---|
58 | // Strip any remaining whitespace |
---|
59 | return trim($t); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | ?> |
---|