下面由thinkphp教程栏目给大家介绍thinkphp里无法输出图片,设置响应头方法,希望对需要的朋友有所帮助!
header("Content-type", "image/jpeg");
ThinkPHP6endor opthinkrameworksrc 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