I am trying to restrict non loggedin users from downloading contents, what I have uploaded in a public directory.I am currently working on Laravel 5.2. So still now what I have done, I just a make a URL which checks the file name and folder name and download the files. In that way, I am hiding my parent folder directory from users. But this is not a good practice because if anybody finds the file URL then they can access it without logging in.
This is my download script:
public function getFile(Request $request)
{
*************
*************
$folderFilePath = public_path('my file directory');
return response()->download($folderFilePath, $filename, []);
}
So, is there a way that can restrict downloads from a particular directory for non logged in users in laravel? Thanks a lot in advance.
The bootstrap directory contains the app.php file which bootstraps the framework. This directory also houses a cache directory which contains framework generated files for performance optimization such as the route and services cache files. You should not typically need to modify any files within this directory.
The files and folders in laravels public folder are meant to be web accessible. For security, all other files and folders in the laravel framework should not be web accessible. Moving the index. php to laravels root will break the framework and defy best practices.
Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.
You should keep the files in the storage
directory which is not accessible for users. Then these files will be protected and authenticated users will still be able to download them:
if (auth()->check()) {
$folderFilePath = storage_path('my file directory');
return response()->download($folderFilePath, $filename, []);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With