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


PHP MIME_Type::getMedia方法代码示例

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


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

示例1: getExtension

 /**
  * Return default MIME-type for the specified extension.
  *
  * @param string $type MIME-type
  *
  * @return string A file extension without leading period.
  */
 function getExtension($type)
 {
     include_once 'MIME/Type.php';
     // Strip parameters and comments.
     $type = MIME_Type::getMedia($type) . '/' . MIME_Type::getSubType($type);
     $extension = array_search($type, $this->extensionToType);
     if ($extension === false) {
         return PEAR::raiseError("Sorry, couldn't determine extension.");
     }
     return $extension;
 }
开发者ID:Dulciane,项目名称:jaws,代码行数:18,代码来源:Extension.php

示例2: wildcardMatch

 /**
  * Perform a wildcard match on a MIME type
  *
  * Example:
  * MIME_Type::wildcardMatch('image/*', 'image/png')
  *
  * @param  string  $card Wildcard to check against
  * @param  string  $type MIME type to check
  * @return boolean true if there was a match, false otherwise
  */
 function wildcardMatch($card, $type)
 {
     if (!MIME_Type::isWildcard($card)) {
         return false;
     }
     if ($card == '*/*') {
         return true;
     }
     if (MIME_Type::getMedia($card) == MIME_Type::getMedia($type)) {
         return true;
     }
     return false;
 }
开发者ID:chajianku,项目名称:admin_eXtplorer,代码行数:23,代码来源:Type.php

示例3: testGetMedia

 /**
  *
  */
 public function testGetMedia()
 {
     $this->assertEquals('text', MIME_Type::getMedia('text/plain'));
     $this->assertEquals('application', MIME_Type::getMedia('application/ogg'));
     $this->assertEquals('*', MIME_Type::getMedia('*/*'));
 }
开发者ID:Bobsel,项目名称:gn-tic,代码行数:9,代码来源:TypeTest.php

示例4: getUploadedFileType

 /**
  * Attempt to identify the content type of a given file.
  * 
  * @param mixed $f file handle resource, or filesystem path as string
  * @param string $originalFilename (optional) for extension-based detection
  * @return string
  * 
  * @fixme is this an internal or public method? It's called from GetFileAction
  * @fixme this seems to tie a front-end error message in, kinda confusing
  * @fixme this looks like it could return a PEAR_Error in some cases, if
  *        type can't be identified and $config['attachments']['supported'] is true
  * 
  * @throws ClientException if type is known, but not supported for local uploads
  */
 static function getUploadedFileType($f, $originalFilename = false)
 {
     require_once 'MIME/Type.php';
     require_once 'MIME/Type/Extension.php';
     // We have to disable auto handling of PEAR errors
     PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
     $mte = new MIME_Type_Extension();
     $cmd =& PEAR::getStaticProperty('MIME_Type', 'fileCmd');
     $cmd = common_config('attachments', 'filecommand');
     $filetype = null;
     // If we couldn't get a clear type from the file extension,
     // we'll go ahead and try checking the content. Content checks
     // are unambiguous for most image files, but nearly useless
     // for office document formats.
     if (is_string($f)) {
         // assuming a filename
         $filetype = MIME_Type::autoDetect($f);
     } else {
         // assuming a filehandle
         $stream = stream_get_meta_data($f);
         $filetype = MIME_Type::autoDetect($stream['uri']);
     }
     // The content-based sources for MIME_Type::autoDetect()
     // are wildly unreliable for office-type documents. If we've
     // gotten an unclear reponse back or just couldn't identify it,
     // we'll try detecting a type from its extension...
     $unclearTypes = array('application/octet-stream', 'application/vnd.ms-office', 'application/zip', 'text/xml');
     if ($originalFilename && (!$filetype || in_array($filetype, $unclearTypes))) {
         $type = $mte->getMIMEType($originalFilename);
         if (is_string($type)) {
             $filetype = $type;
         }
     }
     $supported = common_config('attachments', 'supported');
     if (is_array($supported)) {
         // Normalize extensions to mime types
         foreach ($supported as $i => $entry) {
             if (strpos($entry, '/') === false) {
                 common_log(LOG_INFO, "sample.{$entry}");
                 $supported[$i] = $mte->getMIMEType("sample.{$entry}");
             }
         }
     }
     if ($supported === true || in_array($filetype, $supported)) {
         // Restore PEAR error handlers for our DB code...
         PEAR::staticPopErrorHandling();
         return $filetype;
     }
     $media = MIME_Type::getMedia($filetype);
     if ('application' !== $media) {
         // TRANS: Client exception thrown trying to upload a forbidden MIME type.
         // TRANS: %1$s is the file type that was denied, %2$s is the application part of
         // TRANS: the MIME type that was denied.
         $hint = sprintf(_('"%1$s" is not a supported file type on this server. ' . 'Try using another %2$s format.'), $filetype, $media);
     } else {
         // TRANS: Client exception thrown trying to upload a forbidden MIME type.
         // TRANS: %s is the file type that was denied.
         $hint = sprintf(_('"%s" is not a supported file type on this server.'), $filetype);
     }
     // Restore PEAR error handlers for our DB code...
     PEAR::staticPopErrorHandling();
     throw new ClientException($hint);
 }
开发者ID:jianoll,项目名称:SpeakEnglish_Server,代码行数:77,代码来源:mediafile.php

示例5: getUploadedFileType

 static function getUploadedFileType($f)
 {
     require_once 'MIME/Type.php';
     $cmd =& PEAR::getStaticProperty('MIME_Type', 'fileCmd');
     $cmd = common_config('attachments', 'filecommand');
     $filetype = null;
     if (is_string($f)) {
         // assuming a filename
         $filetype = MIME_Type::autoDetect($f);
     } else {
         // assuming a filehandle
         $stream = stream_get_meta_data($f);
         $filetype = MIME_Type::autoDetect($stream['uri']);
     }
     if (common_config('attachments', 'supported') === true || in_array($filetype, common_config('attachments', 'supported'))) {
         return $filetype;
     }
     $media = MIME_Type::getMedia($filetype);
     if ('application' !== $media) {
         $hint = sprintf(_(' Try using another %s format.'), $media);
     } else {
         $hint = '';
     }
     throw new ClientException(sprintf(_('%s is not a supported file type on this server.'), $filetype) . $hint);
 }
开发者ID:sukhjindersingh,项目名称:PHInest-Solutions,代码行数:25,代码来源:mediafile.php


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