本文整理汇总了PHP中OC_Helper::mimetypes方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Helper::mimetypes方法的具体用法?PHP OC_Helper::mimetypes怎么用?PHP OC_Helper::mimetypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Helper
的用法示例。
在下文中一共展示了OC_Helper::mimetypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMimeType
/**
* get the mimetype form a local file
* @param string path
* @return string
* does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
*/
static function getMimeType($path)
{
$isWrapped = strpos($path, '://') !== false and substr($path, 0, 7) == 'file://';
$mimeType = 'application/octet-stream';
if ($mimeType == 'application/octet-stream') {
self::$mimetypes = (include 'mimetypes.fixlist.php');
$extension = strtolower(strrchr(basename($path), "."));
$extension = substr($extension, 1);
//remove leading .
$mimeType = isset(self::$mimetypes[$extension]) ? self::$mimetypes[$extension] : 'application/octet-stream';
}
if (@is_dir($path)) {
// directories are easy
return "httpd/unix-directory";
}
if ($mimeType == 'application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME)) {
$info = @strtolower(finfo_file($finfo, $path));
if ($info) {
$mimeType = substr($info, 0, strpos($info, ';'));
}
finfo_close($finfo);
}
if (!$isWrapped and $mimeType == 'application/octet-stream' && function_exists("mime_content_type")) {
// use mime magic extension if available
$mimeType = mime_content_type($path);
}
if (!$isWrapped and $mimeType == 'application/octet-stream' && OC_Helper::canExecute("file")) {
// it looks like we have a 'file' command,
// lets see it it does have mime support
$path = escapeshellarg($path);
$fp = popen("file -i -b {$path} 2>/dev/null", "r");
$reply = fgets($fp);
pclose($fp);
//trim the character set from the end of the response
$mimeType = substr($reply, 0, strrpos($reply, ' '));
}
if ($mimeType == 'application/octet-stream') {
// Fallback solution: (try to guess the type by the file extension
if (!self::$mimetypes || self::$mimetypes != (include 'mimetypes.list.php')) {
self::$mimetypes = (include 'mimetypes.list.php');
}
$extension = strtolower(strrchr(basename($path), "."));
$extension = substr($extension, 1);
//remove leading .
$mimeType = isset(self::$mimetypes[$extension]) ? self::$mimetypes[$extension] : 'application/octet-stream';
}
return $mimeType;
}
示例2: getMimeType
/**
* get the mimetype form a local file
* @param string $path
* @return string
* does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
*/
static function getMimeType($path) {
$isWrapped=(strpos($path, '://')!==false) and (substr($path, 0, 7)=='file://');
if (@is_dir($path)) {
// directories are easy
return "httpd/unix-directory";
}
if(strpos($path, '.')) {
//try to guess the type by the file extension
if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') {
self::$mimetypes=include 'mimetypes.list.php';
}
$extension=strtolower(strrchr(basename($path), "."));
$extension=substr($extension, 1);//remove leading .
$mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
}else{
$mimeType='application/octet-stream';
}
if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) {
$info = @strtolower(finfo_file($finfo, $path));
if($info) {
$mimeType=substr($info, 0, strpos($info, ';'));
}
finfo_close($finfo);
}
if (!$isWrapped and $mimeType=='application/octet-stream' && function_exists("mime_content_type")) {
// use mime magic extension if available
$mimeType = mime_content_type($path);
}
if (!$isWrapped and $mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) {
// it looks like we have a 'file' command,
// lets see if it does have mime support
$path=escapeshellarg($path);
$fp = popen("file -i -b $path 2>/dev/null", "r");
$reply = fgets($fp);
pclose($fp);
// we have smth like 'text/x-c++; charset=us-ascii\n'
// and need to eliminate everything starting with semicolon including trailing LF
$mimeType = preg_replace('/;.*/ms', '', trim($reply));
}
return $mimeType;
}