解決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 分享