I have store the file in storage/app/files folder by $path=$request->file->store(\'files\')
and save the path \"files/LKaOlKhE5uITzAbRj5PkkNunWldmUTm3tOWP
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.
I'm using Laravel 6.X and was having a similar issue. The go around according to your issue is as follows: 1)In your routes/web.php do something like
/**sample route**/
Route::get('/download/{path}/', 'MyController@get_file');
2)Then in your controller (MyController.php) for our case it should look like this:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class MyController extends Controller
{
public function get_file($path)
{
/**this will force download your file**/
return response()->download($path);
}
}