2016-04-18 52 views
0

試圖下載一個csv文件,在下載過程中,頁面在新標籤中打開,並在File.php第37行中顯示爲FileNotFoundException的錯誤:文件「72」不存在。任何人都可以幫我嗎?無法下載laravel 5中的文件?

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', '[email protected]'); 

Angularjs控制器:

$scope.exportFile = function(){ 
    $window.open(rootUrl+'fileExport');  
} 

<button class="btn btn-default btn-xs btn-detail" ng-click="exportFile()">Export</button> 

回答

1

異常顯示文件未找到,可能不會發生。

首先檢查文件是否存在,路徑是否正確?

如果文件不存在,那麼讓它簡單的下方,所需的路徑上正確地創建該文件,然後你就可以進入:

$f = fopen($fileName, 'w');