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


PHP OC_Helper::canExecute方法代码示例

本文整理汇总了PHP中OC_Helper::canExecute方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Helper::canExecute方法的具体用法?PHP OC_Helper::canExecute怎么用?PHP OC_Helper::canExecute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OC_Helper的用法示例。


在下文中一共展示了OC_Helper::canExecute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: detect

 /**
  * detect mimetype based on both filename and content
  *
  * @param string $path
  * @return string
  */
 public function detect($path)
 {
     if (@is_dir($path)) {
         // directories are easy
         return "httpd/unix-directory";
     }
     $mimeType = $this->detectPath($path);
     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, ';'));
             return empty($mimeType) ? 'application/octet-stream' : $mimeType;
         }
         finfo_close($finfo);
     }
     $isWrapped = strpos($path, '://') !== false and substr($path, 0, 7) === 'file://';
     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 -b --mime-type {$path} 2>/dev/null", "r");
         $reply = fgets($fp);
         pclose($fp);
         //trim the newline
         $mimeType = trim($reply);
         if (empty($mimeType)) {
             $mimeType = 'application/octet-stream';
         }
     }
     return $mimeType;
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:41,代码来源:detection.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://';
     $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

示例3: 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

示例4: getMimeType

 public function getMimeType($fspath)
 {
     if ($this->is_readable($fspath)) {
         if (@is_dir($this->datadir . $fspath)) {
             // directories are easy
             return "httpd/unix-directory";
         } elseif (function_exists('finfo_open') and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME)) {
             $mimeType = strtolower(finfo_file($finfo, $this->datadir . $fspath));
             $mimeType = substr($mimeType, 0, strpos($mimeType, ';'));
             finfo_close($finfo);
             return $mimeType;
         } else {
             if (function_exists("mime_content_type")) {
                 // use mime magic extension if available
                 $mime_type = mime_content_type($this->datadir . $fspath);
             } else {
                 if (OC_Helper::canExecute("file")) {
                     // it looks like we have a 'file' command,
                     // lets see it it does have mime support
                     $fp = popen("file -i -b '{$this->datadir}{$fspath}' 2>/dev/null", "r");
                     $reply = fgets($fp);
                     pclose($fp);
                     //trim the character set from the end of the response
                     $mime_type = substr($reply, 0, strrpos($reply, ' '));
                 }
             }
         }
         if (empty($mime_type)) {
             // Fallback solution: (try to guess the type by the file extension
             if (!self::$mimetypes) {
                 self::$mimetypes = (include 'mimetypes.list.php');
             }
             $extention = strtolower(strrchr(basename($fspath), "."));
             $extention = substr($extention, 1);
             //remove leading .
             $mime_type = isset(self::$mimetypes[$extention]) ? self::$mimetypes[$extention] : 'application/octet-stream';
         }
         return $mime_type;
     }
 }
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:40,代码来源:owncloud_lib_filestorage_local.php

示例5: scanFile

 /**
  * scan a file for music
  * @param string $path
  * @return boolean
  */
 public static function scanFile($path)
 {
     if (is_null(self::$useMp3Info)) {
         self::$useMp3Info = OC_Helper::canExecute("mp3info");
     }
     $file = OC_Filesystem::getLocalFile($path);
     if (substr($path, -3) == 'mp3' and self::$useMp3Info) {
         //use the command line tool id3info if possible
         $output = array();
         $size = filesize($file);
         exec('mp3info -p "%a\\n%l\\n%t\\n%n\\n%S" "' . $file . '"', $output);
         if (count($output) > 4) {
             $artist = $output[0];
             $album = $output[1];
             $title = $output[2];
             $track = $output[3];
             $length = $output[4];
         } else {
             return;
             //invalid mp3 file
         }
     } else {
         if (!self::isMusic($path)) {
             return;
         }
         if (!self::$getID3) {
             self::$getID3 = @new getID3();
         }
         $data = @self::$getID3->analyze($file);
         getid3_lib::CopyTagsToComments($data);
         if (!isset($data['comments'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading id3 tags in '{$file}'");
             }
             return;
         }
         if (!isset($data['comments']['artist'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading artist tag in '{$file}'");
             }
             $artist = 'unknown';
         } else {
             $artist = stripslashes($data['comments']['artist'][0]);
             $artist = utf8_encode($artist);
         }
         if (!isset($data['comments']['album'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading album tag in '{$file}'");
             }
             $album = 'unknown';
         } else {
             $album = stripslashes($data['comments']['album'][0]);
             $album = utf8_encode($album);
         }
         if (!isset($data['comments']['title'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading title tag in '{$file}'");
             }
             $title = 'unknown';
         } else {
             $title = stripslashes($data['comments']['title'][0]);
             $title = utf8_encode($title);
         }
         $size = $data['filesize'];
         $track = isset($data['comments']['track']) ? $data['comments']['track'][0] : 0;
         $length = isset($data['playtime_seconds']) ? round($data['playtime_seconds']) : 0;
     }
     if (!isset(self::$artists[$artist])) {
         $artistId = OC_MEDIA_COLLECTION::addArtist($artist);
         self::$artists[$artist] = $artistId;
     } else {
         $artistId = self::$artists[$artist];
     }
     if (!isset(self::$albums[$artist . '/' . $album])) {
         $albumId = OC_MEDIA_COLLECTION::addAlbum($album, $artistId);
         self::$albums[$artist . '/' . $album] = $albumId;
     } else {
         $albumId = self::$albums[$artist . '/' . $album];
     }
     $songId = OC_MEDIA_COLLECTION::addSong($title, $path, $artistId, $albumId, $length, $track, $size);
     return !($title == 'unkown' && $artist == 'unkown' && $album == 'unkown') ? $songId : 0;
 }
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:87,代码来源:owncloud_apps_media_lib_scanner.php


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