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


PHP Response::download方法代码示例

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


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

示例1: respondAs

 /**
  * Sets the response header based on type map index name. This wraps several methods
  * available on Cake\Network\Response. It also allows you to use Content-Type aliases.
  *
  * @param string|array $type Friendly type name, i.e. 'html' or 'xml', or a full content-type,
  *    like 'application/x-shockwave'.
  * @param array $options If $type is a friendly type name that is associated with
  *    more than one type of content, $index is used to select which content-type to use.
  * @return bool Returns false if the friendly type name given in $type does
  *    not exist in the type map, or if the Content-type header has
  *    already been set by this method.
  * @see RequestHandlerComponent::setContent()
  */
 public function respondAs($type, array $options = array())
 {
     $defaults = array('index' => null, 'charset' => null, 'attachment' => false);
     $options += $defaults;
     $cType = $type;
     if (strpos($type, '/') === false) {
         $cType = $this->response->getMimeType($type);
     }
     if (is_array($cType)) {
         if (isset($cType[$options['index']])) {
             $cType = $cType[$options['index']];
         }
         if ($this->prefers($cType)) {
             $cType = $this->prefers($cType);
         } else {
             $cType = $cType[0];
         }
     }
     if (!$type) {
         return false;
     }
     if (empty($this->request->params['requested'])) {
         $this->response->type($cType);
     }
     if (!empty($options['charset'])) {
         $this->response->charset($options['charset']);
     }
     if (!empty($options['attachment'])) {
         $this->response->download($options['attachment']);
     }
     return true;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:45,代码来源:RequestHandlerComponent.php

示例2: testDownload

 /**
  * Tests the download method
  *
  * @return void
  */
 public function testDownload()
 {
     $response = new Response();
     $expected = ['Content-Disposition' => 'attachment; filename="myfile.mp3"'];
     $response->download('myfile.mp3');
     $this->assertEquals($expected, $response->header());
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:12,代码来源:ResponseTest.php


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