无法使用php从存储中下载excel / pdf / png文件

时间:2018-02-26 08:11:02

标签: php download laravel-5.3

我无法使用php(laravel版本5.3)从本地存储中下载我的文件。我已完成所有研究,并遵循仍然下载的所有工作。没有错误,但没有下载。

Route::post('api/downloadfile', function($file_name = 'ExportFile.xlsx')
{   
     // file exist on this file path ..\storage\exports\ExportFile.xlsx

     $path = storage_path().'/'.'exports'.'/'.$file_name;

     if (file_exists($path)) {
         ob_end_clean();
         ob_start();             
         return Response::download($path);
     }
});

我甚至尝试过我的回归,但仍然没有工作:

 return response()->download($file);

这是我的响应标题:

 Accept-Ranges:none
 Cache-Control:public
 Connection:close
 Content-Disposition:attachment; filename="ExportFile.xlsx"
 Content-Length:12328
 Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
 Date:Mon, 26 Feb 2018 07:53:32 GMT
 ETag:"da39a3ee5e6b4b0d3255bfef95601890afd80709"
 Host:localhost:8000

我甚至修改了标题。

0 个答案:

没有答案