當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。