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


PHP MIME_Type::_fileAutoDetect方法代码示例

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


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

示例1: autoDetect

 /**
  * Autodetect a file's MIME-type
  *
  * This function may be called staticly.
  *
  * @param  string $file   Path to the file to get the type of
  * @param  bool   $params Append MIME parameters if true
  * @return string $file's MIME-type on success, PEAR_Error otherwise
  * @since 1.0.0beta1
  * @static
  */
 function autoDetect($file, $params = false)
 {
     @(include_once 'System/Command.php');
     if (function_exists('mime_content_type')) {
         $type = mime_content_type($file);
     } else {
         if (class_exists('System_Command')) {
             $type = MIME_Type::_fileAutoDetect($file);
         } else {
             return PEAR::raiseError("Sorry, can't autodetect; you need the mime_magic extension or System_Command and 'file' installed to use this function.");
         }
     }
     // _fileAutoDetect() may have returned an error.
     if (PEAR::isError($type)) {
         return $type;
     }
     // Don't return an empty string
     if (!$type || !strlen($type)) {
         return PEAR::raiseError("Sorry, couldn't determine file type.");
     }
     // Strip parameters if present & requested
     if (MIME_Type::hasParameters($type) && !$params) {
         $type = MIME_Type::stripParameters($type);
     }
     return $type;
 }
开发者ID:chajianku,项目名称:admin_eXtplorer,代码行数:37,代码来源:Type.php

示例2: _autoDetect

 /**
  * Autodetect a file's MIME-type
  *
  * @param string $file   Path to the file to get the type of
  * @param bool   $params Append MIME parameters if true
  *
  * @return string $file's MIME-type on success, PEAR_Error otherwise
  *
  * @since 1.3.0
  *
  * @internal Tries to use fileinfo extension at first. If that
  *  does not work, mime_magic is used. If this is also not available
  *  or does not succeed, "file" command is tried to be executed with
  *  System_Command. When that fails, too, then we use our in-built
  *  extension-to-mimetype-mapping list.
  */
 function _autoDetect($file, $params = false)
 {
     // Sanity checks
     if (!file_exists($file)) {
         return PEAR::raiseError("File \"{$file}\" doesn't exist");
     }
     if (!is_readable($file)) {
         return PEAR::raiseError("File \"{$file}\" is not readable");
     }
     if ($this->useFinfo && function_exists('finfo_file')) {
         $finfo = finfo_open(FILEINFO_MIME, $this->magicFile);
         if ($finfo) {
             $type = finfo_file($finfo, $file);
             finfo_close($finfo);
             if ($type !== false && $type !== '') {
                 return MIME_Type::_handleDetection($type, $params);
             }
         }
     }
     if ($this->useMimeContentType && function_exists('mime_content_type')) {
         $type = mime_content_type($file);
         if ($type !== false && $type !== '') {
             return MIME_Type::_handleDetection($type, $params);
         }
     }
     if ($this->useFileCmd) {
         @(include_once 'System/Command.php');
         if (class_exists('System_Command')) {
             $type = MIME_Type::_fileAutoDetect($file);
             if ($type !== false && $type !== '') {
                 return MIME_Type::_handleDetection($type, $params);
             }
         }
     }
     if ($this->useExtension) {
         include_once 'MIME/Type/Extension.php';
         $mte = new MIME_Type_Extension();
         return $mte->getMIMEType($file);
     }
     return PEAR::raiseError("Sorry, couldn't determine file type.");
 }
开发者ID:MusicalAPP,项目名称:gfk-api-spotify-itunes,代码行数:57,代码来源:Type.php

示例3: autoDetect

 /**
  * Autodetect a file's MIME-type
  *
  * This function may be called staticly.
  *
  * @param  string $file        Path to the file to get the type of
  * @param  string $custom_mime An optional custom 'default' value, mostly used for the filetype sent by the users' browser
  * @param  bool   $params      Append MIME parameters if true
  * @return string $file's      MIME-type on success, false boolean otherwise
  * @since 1.0.0beta1
  * @static
  */
 function autoDetect($file, $custom_mime = null, $custom_ext = null, $params = false)
 {
     if (function_exists('mime_content_type')) {
         $type = mime_content_type($file);
         if ($type == "application/octet-stream" || $type == "application/unknown") {
             if (!empty($custom_mime)) {
                 $type = $custom_mime;
             } elseif (!empty($custom_ext)) {
                 $type = MIME_Helper::convertExtensionToMime($custom_ext);
             }
         }
     } elseif (!empty($custom_mime)) {
         $type = $custom_mime;
     } else {
         $type = MIME_Type::_fileAutoDetect($file);
     }
     // _fileAutoDetect() may have returned an error.
     if ($type === false) {
         return $type;
     }
     //return PEAR::raiseError("Sorry, can't autodetect; you need the mime_magic extension or System_Command and 'file' installed to use this function.");
     if (!MIME_Helper::convertMimeToExtension($type)) {
         $type = MIME_Helper::convertExtensionToMime($custom_mime);
     }
     // flv (Flash Video format) files need exceptional handling (for now I'll provide a fictional mimetype)
     if ($custom_ext == "flv") {
         $type = "video/x-flv";
     }
     // Don't return an empty string
     if (!$type || !strlen($type)) {
         //return PEAR::raiseError("Sorry, couldn't determine file type.");
         return false;
     }
     // Strip parameters if present & requested
     if (MIME_Type::hasParameters($type) && !$params) {
         $type = MIME_Type::stripParameters($type);
     }
     return $type;
 }
开发者ID:BGCX261,项目名称:zoom-gallery-svn-to-git,代码行数:51,代码来源:mime.class.php

示例4: autoDetect

 /**
  * Autodetect a file's MIME-type
  *
  * This function may be called staticly.
  *
  * @internal Tries to use fileinfo extension at first. If that
  *  does not work, mime_magic is used. If this is also not available
  *  or does not succeed, "file" command is tried to be executed with
  *  System_Command. When that fails, too, then we use our in-built
  *  extension-to-mimetype-mapping list.
  *
  * @param string $file   Path to the file to get the type of
  * @param bool   $params Append MIME parameters if true
  *
  * @return string $file's MIME-type on success, PEAR_Error otherwise
  *
  * @since 1.0.0beta1
  * @static
  */
 function autoDetect($file, $params = false)
 {
     // Sanity checks
     if (!file_exists($file)) {
         return PEAR::raiseError("File \"{$file}\" doesn't exist");
     }
     if (!is_readable($file)) {
         return PEAR::raiseError("File \"{$file}\" is not readable");
     }
     // modifications by brusch for pimcore
     require_once 'MIME/Type/Extension.php';
     $mte = new MIME_Type_Extension();
     if ($type = $mte->getMIMEType($file)) {
         if (!PEAR::isError($type)) {
             return $type;
         }
     }
     if (function_exists('finfo_file')) {
         $finfo = finfo_open(FILEINFO_MIME);
         $type = finfo_file($finfo, $file);
         finfo_close($finfo);
         if ($type !== false && $type !== '') {
             return MIME_Type::_handleDetection($type, $params);
         }
     }
     if (function_exists('mime_content_type')) {
         $type = mime_content_type($file);
         if ($type !== false && $type !== '') {
             return MIME_Type::_handleDetection($type, $params);
         }
     }
     @(include_once 'System/Command.php');
     if (class_exists('System_Command')) {
         return MIME_Type::_handleDetection(MIME_Type::_fileAutoDetect($file), $params);
     }
 }
开发者ID:shanky0110,项目名称:pimcore-custom,代码行数:55,代码来源:Type.php

示例5: autoDetect

 /**
  * Autodetect a file's MIME-type
  *
  * This function may be called staticly.
  *
  * @internal Tries to use fileinfo extension at first. If that
  *  does not work, mime_magic is used. If this is also not available
  *  or does not succeed, "file" command is tried.
  *
  * @param string $file   Path to the file to get the type of
  * @param bool   $params Append MIME parameters if true
  *
  * @return string $file's MIME-type on success, PEAR_Error otherwise
  *
  * @since 1.0.0beta1
  * @static
  */
 function autoDetect($file, $params = false)
 {
     // Sanity checks
     if (!file_exists($file)) {
         return PEAR::raiseError("File \"{$file}\" doesn't exist");
     }
     if (!is_readable($file)) {
         return PEAR::raiseError("File \"{$file}\" is not readable");
     }
     if (function_exists('finfo_file')) {
         $finfo = finfo_open(FILEINFO_MIME);
         $type = finfo_file($finfo, $file);
         finfo_close($finfo);
         if ($type !== false && $type !== '') {
             return MIME_Type::_handleDetection($type, $params);
         }
     }
     if (function_exists('mime_content_type')) {
         $type = mime_content_type($file);
         if ($type !== false && $type !== '') {
             return MIME_Type::_handleDetection($type, $params);
         }
     }
     @(include_once 'System/Command.php');
     if (class_exists('System_Command')) {
         return MIME_Type::_handleDetection(MIME_Type::_fileAutoDetect($file), $params);
     }
     return PEAR::raiseError("Sorry, can't autodetect; you need the fileinfo or" . " mime_magic extension" . " or System_Command and 'file' installed" . " to use this function.");
 }
开发者ID:quangbt2005,项目名称:vhost-kis,代码行数:46,代码来源:Type.php


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