本文整理匯總了PHP中f::mimeToExtension方法的典型用法代碼示例。如果您正苦於以下問題:PHP f::mimeToExtension方法的具體用法?PHP f::mimeToExtension怎麽用?PHP f::mimeToExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類f
的用法示例。
在下文中一共展示了f::mimeToExtension方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: to
public function to()
{
if (!is_null($this->to)) {
return $this->to;
}
$source = $this->source();
$name = f::name($source['name']);
$extension = f::extension($source['name']);
$safeName = f::safeName($name);
$safeExtension = str_replace('jpeg', 'jpg', str::lower($extension));
if (empty($safeExtension)) {
$safeExtension = f::mimeToExtension(f::mime($source['tmp_name']));
}
return $this->to = str::template($this->options['to'], array('name' => $name, 'filename' => $source['name'], 'safeName' => $safeName, 'safeFilename' => $safeName . r(!empty($safeExtension), '.' . $safeExtension), 'extension' => $extension, 'safeExtension' => $safeExtension));
}
示例2: mime
/**
* Returns the mime type of a file
*
* @param string $file
* @return mixed
*/
public static function mime($file)
{
// stop for invalid files
if (!file_exists($file)) {
return null;
}
// Fileinfo is prefered if available
if (function_exists('finfo_file')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $file);
finfo_close($finfo);
return $mime;
}
// for older versions with mime_content_type go for that.
if (function_exists('mime_content_type') && ($mime = @mime_content_type($file) !== false)) {
return $mime;
}
// shell check
try {
$mime = system::execute('file', [$file, '-z', '-b', '--mime'], 'output');
$mime = trim(str::split($mime, ';')[0]);
if (f::mimeToExtension($mime)) {
return $mime;
}
} catch (Exception $e) {
// no mime type detectable with shell
$mime = null;
}
// Mime Sniffing
$reader = new MimeReader($file);
$mime = $reader->get_type();
if (!empty($mime) && f::mimeToExtension($mime)) {
return $mime;
}
// guess the matching mime type by extension
return f::extensionToMime(f::extension($file));
}