I'm creating a CMS wherein I can upload files(photos, pdf, etc) using Laravel's file upload. What I'm doing differently is that I want to store the file outside my CMS project directory let's say my website's storage folder. BTW I'm creating two different projects
Laravel documentation says that I can change the path where it will be uploaded in the filesystems.php what I did is get the relative path of my website storage folder and paste it here(see below).
'local' => [
'driver' => 'local', //here
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
As expected it's not working. Any help guys?
In Laravel 5 it this works by using $app->useStoragePath('/path/') in bootstrap/app. php .
You could use PHP's unlink() method just as @Khan suggested. But if you want to do it the Laravel way, use the File::delete() method instead. $files = array($file1, $file2); File::delete($files);
When using the local driver, all files that should be publicly accessible should be placed in the storage/app/public directory. Furthermore, you should create a symbolic link at public/storage which points to the storage/app/public directory.
You can add multiple disk in your file system.
Just locate on same website storage folder
Example:
Project 1:
'disks' => [
'custom_folder_1' => [
'driver' => 'local',
'root' => '../path/to/your/new/storage/folder',
],
]
Project 2:
'disks' => [
'custom_folder_2' => [
'driver' => 'local',
'root' => '../path/to/your/new/storage/folder',
],
]
the path should be the same location.
../path/to/your/new/storage/folder
and then you can use it like:
Storage::disk('custom_folder_1')->put('filename1', $file_content);
Storage::disk('custom_folder_2')->put('filename2', $file_content);
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