<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * mime_content_type() file
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category   PHP
 * @package    PHP_Compat
 * @link       http://pear.php.net/package/PHP_Compat
 * @version    CVS: $Revision$
 * @author     Ian Eure <ieure@php.net>
 * @copyright  (c) 2005 Ian Eure
 */


/**
 * Replace mime_content_type()
 *
 * You will need the `file' command installed and present in your $PATH. If
 * `file' is not available, the type 'application/octet-stream' is returned
 * for all files.
 *
 * @category   PHP
 * @package    PHP_Compat
 * @link       http://php.net/function.mime_content_type
 * @version    CVS: $Revision$
 * @author     Ian Eure <ieure@php.net>
 * @copyright  (c) 2005 Ian Eure
 * @since      PHP 4.3.0
 * @require    PHP 4.0.3 (escapeshellarg)
 */
if (!function_exists('_mime_content_type')) {
    function 
_mime_content_type($filename)
    {
        
$filename escapeshellarg($filename);
        
$out = `file -iL $filename 2>/dev/null`;
        if (empty(
$out)) {
            return 
'application/octet-stream';
        }

        
// Strip off filename
        
$t substr($outstrpos($out':') + 2);

        if (
strpos($t';') !== false) {
            
// Strip MIME parameters
            
$t substr($t0strpos($t';'));
        }

        
// Strip any remaining whitespace
        
return trim($t);
    }
}
?>