gpt4 book ai didi

php - 由于 Laravel 中的 header ,响应::下载错误

转载 作者:行者123 更新时间:2023-12-03 21:36:46 25 4
gpt4 key购买 nike

Controller :

public function download(){

$headers = array('Content-Type' => 'text/csv');
return Response::download('download.csv', 'download.csv', $headers)->setContentDisposition('inline');

}

筛选:
 $response->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');

错误:
 [2016-01-19 15:34:29] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::header()' in C:\xampp\htdocs\development\app\filters.php:60
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleShutdown()
#1 {main} [] []

我不知道如何解决这种问题。我已经试过了 this但仍然无法正常工作。

最佳答案

https://github.com/palanik/lumen-cors/issues/9

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next) {

if ($request->isMethod('OPTIONS')) {
$response = new Response("", 200);
}
else {
$response = $next($request);
}

// Added this to fix the image download problem
// Only set Cors if its not een image
if(strpos($response->headers->get('content-type'), 'image') === false) {
$this->setCorsHeaders($request, $response);
}

return $response;
}

关于php - 由于 Laravel 中的 header ,响应::下载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34871123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com