尝试下载csv文件,在下载页面期间在新标签页中打开,并在File.php第37行显示错误为FileNotFoundException
:文件" 72"不存在。 Ccan有人请帮帮我吗?
Laravel控制器:
public function fileExport(Request $request, Response $response)
{
$employee = Employee::all()->toArray();
$fileName = 'Employee.csv';
$headers = array(header('Content-Type: application/csv', 'Content-Disposition: attachment; filename="'.$fileName.'"'));
$f = fopen('php://output', 'w');
foreach ($employee as $line)
{
$data = fputcsv($f, $line);
}
return response()->download($data,$headers);
}
Laravel路由器:
Route::get('fileExport', 'EmployeeController@fileExport');
Angularjs控制器:
$scope.exportFile = function(){
$window.open(rootUrl+'fileExport');
}
<button class="btn btn-default btn-xs btn-detail" ng-click="exportFile()">Export</button>
答案 0 :(得分:1)
异常显示找不到文件,可能无法生成。
首先检查文件是否存在且路径是否正确?
如果文件不存在,请按照下面的说法进行操作,并在所需的路径上正确创建文件,然后继续:
$f = fopen($fileName, 'w');