gpt4 book ai didi

php - 调用未定义的方法 Symfony\\Component\\HttpFoundation\\StreamedResponse::status()

转载 作者:搜寻专家 更新时间:2023-10-31 21:49:06 25 4
gpt4 key购买 nike

Laravel 版本:5.2.45PHP 版本:PHP 版本 7.0.22-0ubuntu0.16.04.1

调用未定义的方法 Symfony\Component\HttpFoundation\StreamedResponse::status()我正在尝试使用以下代码下载 csv 但出现错误

我的代码:

$headers = array(
"Content-type" => "text/csv",
"Content-Disposition" => "attachment; filename=file.csv",
"Pragma" => "no-cache",
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Expires" => "0",
);

$columns = array('userId', 'action', 'value', 'ipAddress', 'createdOn');

$callback = function () use ($data, $columns) {
$file = fopen('php://output', 'w');

fputcsv($file, $columns);

foreach ($data as $item) {
fputcsv($file, array($item['userId'], $item['action'], $item['value'], $item['ipAddress'], $item['createdOn']));
}

fclose($file);
};

return FacadeResponse::stream($callback, 200, $headers);

最佳答案

use Response; 在文件顶部,然后编辑此行:

return FacadeResponse::stream($callback, 200, $headers);

为此:

return Response::stream($callback, 200, $headers);

关于php - 调用未定义的方法 Symfony\\Component\\HttpFoundation\\StreamedResponse::status(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47670492/

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