Reputation: 79
trying to download a csv file, during downloading the page is opened in new tab and showing the error as FileNotFoundException
in File.php line 37: The file "72" does not exist. Ccan anyone please help me?
Laravel controller:
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 router:
Route::get('fileExport', 'EmployeeController@fileExport');
Angularjs controller:
$scope.exportFile = function(){
$window.open(rootUrl+'fileExport');
}
<button class="btn btn-default btn-xs btn-detail" ng-click="exportFile()">Export</button>
Upvotes: 0
Views: 520
Reputation: 617
Exception shows that file is not found and might not be generated.
First of all check file exists and paths are correct?
And if file does not exists then make it simple as below and create the file correctly on desired path and then you can move on:
$f = fopen($fileName, 'w');
Upvotes: 1