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


PHP CakeResponse::getMimeType方法代码示例

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


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

示例1: mapAlias

/**
 * Maps a content type alias back to its mime-type(s)
 *
 * @param string|array $alias String alias to convert back into a content type. Or an array of aliases to map.
 * @return string Null on an undefined alias. String value of the mapped alias type. If an
 *   alias maps to more than one content type, the first one will be returned.
 */
	public function mapAlias($alias) {
		if (is_array($alias)) {
			return array_map(array($this, 'mapAlias'), $alias);
		}
		$type = $this->response->getMimeType($alias);
		if ($type) {
			if (is_array($type)) {
				return $type[0];
			}
			return $type;
		}
		return null;
	}
开发者ID:hungnt88,项目名称:5stars-1,代码行数:20,代码来源:RequestHandlerComponent.php

示例2: media

 /**
  * Returns an audio/video element
  *
  * ### Usage
  *
  * Using an audio file:
  *
  * `echo $this->Html->media('audio.mp3', array('fullBase' => true));`
  *
  * Outputs:
  *
  * `<video src="http://www.somehost.com/files/audio.mp3">Fallback text</video>`
  *
  * Using a video file:
  *
  * `echo $this->Html->media('video.mp4', array('text' => 'Fallback text'));`
  *
  * Outputs:
  *
  * `<video src="/files/video.mp4">Fallback text</video>`
  *
  * Using multiple video files:
  *
  * ```
  * echo $this->Html->media(
  * 		array('video.mp4', array('src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'")),
  * 		array('tag' => 'video', 'autoplay')
  * );
  * ```
  *
  * Outputs:
  *
  * ```
  * <video autoplay="autoplay">
  * 		<source src="/files/video.mp4" type="video/mp4"/>
  * 		<source src="/files/video.ogv" type="video/ogv; codecs='theora, vorbis'"/>
  * </video>
  * ```
  *
  * ### Options
  *
  * - `tag` Type of media element to generate, either "audio" or "video".
  * 	If tag is not provided it's guessed based on file's mime type.
  * - `text` Text to include inside the audio/video tag
  * - `pathPrefix` Path prefix to use for relative URLs, defaults to 'files/'
  * - `fullBase` If provided the src attribute will get a full address including domain name
  *
  * @param string|array $path Path to the video file, relative to the webroot/{$options['pathPrefix']} directory.
  *  Or an array where each item itself can be a path string or an associate array containing keys `src` and `type`
  * @param array $options Array of HTML attributes, and special options above.
  * @return string Generated media element
  */
 public function media($path, $options = array())
 {
     $options += array('tag' => null, 'pathPrefix' => 'files/', 'text' => '');
     if (!empty($options['tag'])) {
         $tag = $options['tag'];
     } else {
         $tag = null;
     }
     if (is_array($path)) {
         $sourceTags = '';
         foreach ($path as &$source) {
             if (is_string($source)) {
                 $source = array('src' => $source);
             }
             if (!isset($source['type'])) {
                 $ext = pathinfo($source['src'], PATHINFO_EXTENSION);
                 $source['type'] = $this->response->getMimeType($ext);
             }
             $source['src'] = $this->assetUrl($source['src'], $options);
             $sourceTags .= $this->useTag('tagselfclosing', 'source', $source);
         }
         unset($source);
         $options['text'] = $sourceTags . $options['text'];
         unset($options['fullBase']);
     } else {
         if (empty($path) && !empty($options['src'])) {
             $path = $options['src'];
         }
         $options['src'] = $this->assetUrl($path, $options);
     }
     if ($tag === null) {
         if (is_array($path)) {
             $mimeType = $path[0]['type'];
         } else {
             $mimeType = $this->response->getMimeType(pathinfo($path, PATHINFO_EXTENSION));
         }
         if (preg_match('#^video/#', $mimeType)) {
             $tag = 'video';
         } else {
             $tag = 'audio';
         }
     }
     if (isset($options['poster'])) {
         $options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => Configure::read('App.imageBaseUrl')) + $options);
     }
     $text = $options['text'];
     $options = array_diff_key($options, array('tag' => null, 'fullBase' => null, 'pathPrefix' => null, 'text' => null));
     return $this->tag($tag, $text, $options);
//.........这里部分代码省略.........
开发者ID:earea2,项目名称:cde_azul,代码行数:101,代码来源:HtmlHelper.php

示例3: insertFile

 /**
  * https://developers.google.com/drive/v2/reference/files/insert
  **/
 public function insertFile($file, $driveFile, $options = array())
 {
     // setting default options
     $options = array_merge(array('convert' => 'true'), $options);
     // seting path and request
     $path = sprintf('/%s', $driveFile['id']);
     $request = array();
     $request['uri']['query'] = $options;
     $request['body'] = file_get_contents($file['tmp_name']);
     // using CakeReponse to guess mime type
     $ext = array_pop(explode('.', $file['name']));
     $CR = new CakeResponse();
     $request['header']['Content-Type'] = $CR->getMimeType($ext);
     return $this->_request($path, $request);
 }
开发者ID:kaburk,项目名称:CakePHP-Google,代码行数:18,代码来源:GoogleDriveFilesUpload.php

示例4: testConstruct

 /**
  * Tests the request object constructor
  *
  * @return void
  */
 public function testConstruct()
 {
     $response = new CakeResponse();
     $this->assertNull($response->body());
     $this->assertEquals('UTF-8', $response->charset());
     $this->assertEquals('text/html', $response->type());
     $this->assertEquals(200, $response->statusCode());
     $options = array('body' => 'This is the body', 'charset' => 'my-custom-charset', 'type' => 'mp3', 'status' => '203');
     $response = new CakeResponse($options);
     $this->assertEquals('This is the body', $response->body());
     $this->assertEquals('my-custom-charset', $response->charset());
     $this->assertEquals('audio/mpeg', $response->type());
     $this->assertEquals(203, $response->statusCode());
     $options = array('body' => 'This is the body', 'charset' => 'my-custom-charset', 'type' => 'mp3', 'status' => '422', 'statusCodes' => array(422 => 'Unprocessable Entity'));
     $response = new CakeResponse($options);
     $this->assertEquals($options['body'], $response->body());
     $this->assertEquals($options['charset'], $response->charset());
     $this->assertEquals($response->getMimeType($options['type']), $response->type());
     $this->assertEquals($options['status'], $response->statusCode());
 }
开发者ID:4Queen,项目名称:php-buildpack,代码行数:25,代码来源:CakeResponseTest.php


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