本文整理匯總了PHP中Thin\File::mime方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::mime方法的具體用法?PHP File::mime怎麽用?PHP File::mime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Thin\File
的用法示例。
在下文中一共展示了File::mime方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: openImage
/**
* Open a file, detect its mime-type and create an image resrource from it.
* @param array $file Attributes of file from the $_FILES array
* @return mixed
*/
private function openImage($file)
{
// If $file isn't an array, we'll turn it into one.
if (!is_array($file)) {
$file_dimensions = getimagesize($file);
$file = array('type' => Inflector::lower($file_dimensions['mime']), 'tmp_name' => $file);
}
$mime = $file['type'];
$file_path = $file['tmp_name'];
// Confirm that the file actually exists.
if (!file_exists($file_path)) {
throw new Exception('Could not find file: ' . $file_path . '. It doesn\'t seem to exist.');
}
switch ($mime) {
case 'image/pjpeg':
// IE6
// IE6
case File::mime('jpg'):
$img = @imagecreatefromjpeg($file_path);
break;
case File::mime('gif'):
$img = @imagecreatefromgif($file_path);
break;
case File::mime('png'):
$img = @imagecreatefrompng($file_path);
break;
default:
$img = false;
break;
}
return $img;
}