php laravel文件下載顯示文件損壞

php laravel文件下載顯示文件損壞

  • 問題,服務器中我們保存的文件,直接打開是能夠正常打開,下載下來顯示損壞,如下:
  • 解決方法:下載文件之前清理緩存
    下載文件顯示文件損壞

laravel文件下載

$file_path = storage_path('app\uploads\20200326154132_5e7c5cac3a894.xlsx');//文件地址
    ob_clean();//清理緩存
        
 return response()->download($file_path);

php文件下載

       $name =basename($file_path);
        header("Content-type: application/octet-stream");
       header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
       header("Content-Length: ". filesize($file_path));
        ob_clean();
        flush();
       readfile($file_path);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章