当前位置: 首页>>代码示例>>PHP>>正文


PHP OC_Helper::mimetypes方法代码示例

本文整理汇总了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;
 }
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:54,代码来源:helper.php

示例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;
	}
开发者ID:ryanshoover,项目名称:core,代码行数:52,代码来源:helper.php


注:本文中的OC_Helper::mimetypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。