本文整理汇总了PHP中valid_src_mime_type函数的典型用法代码示例。如果您正苦于以下问题:PHP valid_src_mime_type函数的具体用法?PHP valid_src_mime_type怎么用?PHP valid_src_mime_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了valid_src_mime_type函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mime_type
/**
* 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;
}
示例2: mime_type
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;
}
示例3: mime_type
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;
}
示例4: list
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)