本文整理汇总了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));
}