解决ThinkPHP里无法输出图片问题(关于设置响应头)

下面由thinkphp教程栏目给大家介绍thinkphp里无法输出图片,设置响应头方法,希望对需要的朋友有所帮助!

解决ThinkPHP里无法输出图片问题(关于设置响应头)

thinkphp解决ThinkPHP里无法输出图片问题(关于设置响应头)

header("Content-type", "image/jpeg");
ThinkPHP6endor	opthinkrameworksrc	hinkResponse.php
$file = new File('123.jpg'); $response = $file->mimeType('image/jpeg');  throw new HttpResponseException($response);
 /**      * 创建Response对象      * @access public      * @param  mixed  $data 输出数据      * @param  string $type 输出类型      * @param  int    $code 状态码      * @return Response      */     public static function create($data = '', string $type = 'html', int $code = 200): Response     {         $class = false !== strpos($type, '') ? $type : 'thinkresponse' . ucfirst(strtolower($type));          return Container::getInstance()->invokeClass($class, [$data, $code]);     }
/**  * Html Response  */ class Html extends Response {     /**      * 输出type      * @var string      */     protected $contentType = 'text/html';      public function __construct(Cookie $cookie, $data = '', int $code = 200)     {         $this->init($data, $code);         $this->cookie = $cookie;     } }
/**  * Html Response  */ class Jpeg extends Response {     /**      * 输出type      * @var string      */     protected $contentType = 'image/jpeg';      public function __construct(Cookie $cookie, $data = '', int $code = 200)     {         $this->init($data, $code);         $this->cookie = $cookie;     } }
$response = Response::create('', 'Jpeg'); $image->blob('JPEG'); throw new HttpResponseException($response);

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享