Esempio n. 1
0
/**
 * determine the file mime type
 */
function mime_type($file)
{
    if (stristr(PHP_OS, 'WIN')) {
        $os = 'WIN';
    } else {
        $os = PHP_OS;
    }
    $mime_type = '';
    if (function_exists('mime_content_type') && $os != 'WIN') {
        $mime_type = mime_content_type($file);
    }
    // use PECL fileinfo to determine mime type
    if (!valid_src_mime_type($mime_type)) {
        if (function_exists('finfo_open')) {
            $finfo = @finfo_open(FILEINFO_MIME);
            if ($finfo != '') {
                $mime_type = finfo_file($finfo, $file);
                finfo_close($finfo);
            }
        }
    }
    // try to determine mime type by using unix file command
    // this should not be executed on windows
    if (!valid_src_mime_type($mime_type) && $os != "WIN") {
        if (preg_match("/FreeBSD|FREEBSD|LINUX/", $os)) {
            $mime_type = trim(@shell_exec('file -bi ' . escapeshellarg($file)));
        }
    }
    // use file's extension to determine mime type
    if (!valid_src_mime_type($mime_type)) {
        // set defaults
        $mime_type = 'image/png';
        // file details
        $fileDetails = pathinfo($file);
        $ext = strtolower($fileDetails["extension"]);
        // mime types
        $types = array('jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif');
        if (strlen($ext) && strlen($types[$ext])) {
            $mime_type = $types[$ext];
        }
    }
    return $mime_type;
}
Esempio n. 2
0
function mime_type($file)
{
    $os = strtolower(php_uname());
    $mime_type = '';
    // use PECL fileinfo to determine mime type
    if (function_exists('finfo_open')) {
        $finfo = finfo_open(FILEINFO_MIME);
        $mime_type = finfo_file($finfo, $file);
        finfo_close($finfo);
    }
    // try to determine mime type by using unix file command
    // this should not be executed on windows
    if (!valid_src_mime_type($mime_type) && !eregi('windows', php_uname())) {
        if (preg_match("/freebsd|linux/", $os)) {
            $mime_type = trim(@shell_exec('file -bi $file'));
        }
    }
    // use file's extension to determine mime type
    if (!valid_src_mime_type($mime_type)) {
        $frags = split("\\.", $file);
        $ext = strtolower($frags[count($frags) - 1]);
        $types = array('jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif');
        if (strlen($ext) && strlen($types[$ext])) {
            $mime_type = $types[$ext];
        }
        // if no extension provided, default to jpg
        if (!strlen($ext) && !valid_src_mime_type($mime_type)) {
            $mime_type = 'image/jpeg';
        }
    }
    return $mime_type;
}
Esempio n. 3
0
function mime_type($file)
{
    $os = strtolower(php_uname());
    $mime_type = '';
    // use PECL fileinfo to determine mime type
    if (function_exists('finfo_open')) {
        $finfo = finfo_open(FILEINFO_MIME);
        $mime_type = finfo_file($finfo, $file);
        finfo_close($finfo);
    }
    // try to determine mime type by using unix file command
    // this should not be executed on windows
    if (!valid_src_mime_type($mime_type) && !eregi('windows', $os)) {
        if (preg_match("/freebsd|linux/", $os)) {
            $mime_type = trim(@shell_exec('file -bi $file'));
        }
    }
    // use file's extension to determine mime type
    if (!valid_src_mime_type($mime_type)) {
        // set defaults
        $mime_type = 'image/jpeg';
        // file details
        $fileDetails = pathinfo($file);
        $ext = strtolower($fileDetails["extension"]);
        // mime types
        $types = array('jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif');
        if (strlen($ext) && strlen($types[$ext])) {
            $mime_type = $types[$ext];
        }
    }
    return $mime_type;
}
Esempio n. 4
0
list($img, $thumb_w, $thumb_h, $t_quality, $nonce) = explode('|', $data);
// validate passed data not tampered with
$data = $img . '|' . $thumb_w . '|' . $thumb_h . '|' . $t_quality;
$FUNCS->validate_nonce('jcrop_image_' . $data, $nonce);
$img = base64_decode($img);
if (extension_loaded('gd') && function_exists('gd_info')) {
    $src = $Config['UserFilesAbsolutePath'] . 'image/' . $img;
    if (file_exists($src)) {
        // create thumbnail
        // Adapted from TimThumb script created by Tim McDaniels and Darren Hoyt with tweaks by Ben Gillbanks
        // http://code.google.com/p/timthumb/
        ini_set('memory_limit', "64M");
        // get mime type of src
        $mime_type = mime_type($src);
        // make sure that the src is gif/jpg/png
        if (!valid_src_mime_type($mime_type)) {
            die("Invalid src mime type: " . $mime_type);
        }
        // open the existing image
        $image = open_image($mime_type, $src);
        if ($image === false) {
            die('Unable to open image : ' . $src);
        }
        // fabricate thumbnail name
        $path_parts = $FUNCS->pathinfo($src);
        if (!$thumb_w || !$thumb_h) {
            // freeform selection
            // dimensions of the thumbnail will be taken from the selected area of src
            $thumb_w = $img_w;
            $thumb_h = $img_h;
            // name of the thumbnail will, however, contain the original width and height of src (to match the name given by core 'thumbnail' editable region)