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

标签 php laravel-4

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/

相关文章:

php - 无法使用 PHP 从一个页面获取信息到另一个页面

php - 模型->保存()在 Yii 中不起作用 -> 显示 ' error '

javascript - 将html代码返回给jquery好不好?

PHP Date - 如何添加一个字符串来分隔日期和时间

Laravel 表单不会 PATCH,只会 POST - 嵌套 RESTfull Controller 、MethodNotAllowedHttpException

php - 在远程服务器上运行 beanstalkd worker

php - Woocommerce:要替换哪个 Hook 已弃用 "woocommerce_add_order_item_meta"

php - 访问 Laravel 4 中的包 Controller

php - Laravel 4 重复数据库条目

php - Laravel:Auth::user()->id 试图获取非对象的属性