Cannot download file from storage folder in laravel 5.4

前端 未结 2 2023
误落风尘
误落风尘 2020-12-11 09:18

I have store the file in storage/app/files folder by $path=$request->file->store(\'files\') and save the path \"files/LKaOlKhE5uITzAbRj5PkkNunWldmUTm3tOWP

2条回答
  •  暖寄归人
    2020-12-11 09:41

    Problem is storage folder is not publicly accessible in default. Storage folder is most likely forsave some private files such as users pictures which is not accessible by other users. If you move them to public folder files will be accessible for everyone. I had similar issue with Laravel 5.4 and I did a small go around by writing a route to download files.

    Route::get('files/{file_name}', function($file_name = null)
    {
        $path = storage_path().'/'.'app'.'/files/'.$file_name;
        if (file_exists($path)) {
            return Response::download($path);
        }
    });
    

    Or you can save your files into public folder up to you.

提交回复
热议问题