Adding Custom path for storage in filesystems.php Laravel - php

I want to add a path "C:\Folder" for storage purposes in filesystems.php
When I use the below code I get an error:
Driver [] is not supported.
Code:
'c_path' => [
'driver' => 'local',
'root' => "C:/Folder/",
],
So how to solve this problem? Can someone please suggest me a solution?

From terminal run,
composer require league/flysystem
In your file filesystems.php file
'c_path' => [
'driver' => 'local',
'root' => 'C:\uploads'
],
then for store your file,
Storage::disk('c_path')->put('picture.png', $request->file('picture'));

Related

Fetch Laravel Storage files that are in the storage/folder directory not in storage/app/directory

I'm attempting to pull in a certs file from the directory /storage/certs/certexample.pem in my laravel 6 application.
Whenever I try to run the command:
Storage::get('storage/certs/certexample.pem'))
or use
storage_path('certs')
to fetch the full path I get the error:
League\Flysystem\FileNotFoundException: File not found at path:
The file does exist and I can cat it out on the terminal so there must be something I'm missing.
My filesystem config looks like this:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
I've tried adding in another disk called 'certs' that has storage_path('certs') set however this doesn't seem to help.
Since the file is only ever placed on the server and the app isn't writing it I don't need to write the file using Storage as I've seen in the docs. Is there a way to pull the certsexample.pem file (or a similar file) in this manner or am I missing something with Laravel's Storage functionality?
Update:
After attempting to get a folder to be accessed outside of storage/app with no luck I ended up using the sotrage/app/certs directory and accessing it with storage_path('app/certs').
I had the same problem. I updated config file in config/filesystems.php and added my folder in /storage:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
//my custom directory in storage folder
'orders' => [
'driver' => 'local',
'root' => storage_path('egrn/orders'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
//...default config code
],
And I got the file like:
$storage = Storage::disk('orders')
->get('/kv66cba66ca6cf667995888bf12cc4d25d.xml');
Full path is /storage/egrn/orders/kv66cba66ca6cf667995888bf12cc4d25d.xml

How to delete folder (and its content) not under storage/app in Laravel?

I know we can use Storage::delete() or File::delete to delete folders and/or files in laravel, but this seems not working for folders directly under storage, I mean storage/tmp by example. It only works for storage/app.
How to deal with this?
if (file_exists( storage_path() . '/tmp/file1'.'.pdf' )) {
File::delete(storage_path() . '/tmp/file1'.'.pdf') );
}
Thanks
You can define a new disk in config/filesystems.php with the storage folder as root:
'disks' => [
...
'storage' => [
'driver' => 'local',
'root' => storage_path(),
],
...
],
Then you can delete a folder, such as tmp, like this:
Storage::disk('storage')->deleteDirectory('tmp');
that happen due you have the default configuration in filesystems config, go to config folder
config/filesystems.php
and in the disk property you can modify or add a new key
When you use the Storage directly without call the disk method Laravel will use the default disk called 'local'
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
]
How you can see the root key start in app folder, so when you use Storage::delete() always will delete all inside app folder, the solution can be alter de root key of local disk
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path(),
]
Of this way now when you call the Storage the root will by storage path directly, but the best way its add a new key and don't overwrite the default config
'disks' => [
'storage' => [
'driver' => 'storage',
'root' => storage_path(),
]
And now you can use the new disk of this way:
Storage::disk('storage')->delete('x')

Laravel upload a file to different storage outside the project directory

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?
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);

How to enable mount network disk in elfinder laravel for google drive

I have question of elfinder, how to enable 'Mount Network Disk' on elfinder for use google drive in laravel 5.2. Could tell you me, which are steps to follow.
The steps i followed were:
Installation with composer.
composer require barryvdh/laravel-elfinder
Add the ServiceProvider to the providers array in app/config/app.php
Barryvdh\Elfinder\ElfinderServiceProvider::class
Copy the assets to the public folder, using the following artisan command:
php artisan elfinder:publish
Run command.
composer update
I used the default configuration, I created the folder 'files' in the public folder.
With the command
php artisan vendor:publish --provider='Barryvdh\Elfinder\ElfinderServiceProvider' --tag=config
and
php artisan vendor:publish --provider='Barryvdh\Elfinder\ElfinderServiceProvider' --tag=views
In the file elfinder.php with the route
'vendor/barryvdh/laravel-elfinder/config/elfinder.php'
In the section route use
'route' => [
'prefix' => 'elfinder',
'middleware' => null, //Set to null to disable middleware filter
]
In the file filesystems.php with the route
'/config/filesystems.php'.
In the section disk in the option public, add the line
'root' => base_path().'app/public',
after of the line
'driver' => 'local',
Example:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => base_path().'app/public',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
],
],
This is how i solved the error that occurs when you use the copy option, open folder, etc.
Error, Unable to connect to backend. HTTP error 0
But I do not know, what is needed to use the mount network disk.And
how to give the folder(example: Reading)
This is link of the project
https://github.com/AlonsoCauich/driveOne

Voyager admin panel on Laravel 5.3 could not find a storage symlink

Help guys: I tried to test the new Laravel admin and got the following error:
Missing storage symlink We could not find a storage symlink. This
could cause problems with loading media files from the browser.
I tried to use:
php artisan storage:link
Set in Nginx config:
disable_symlinks off;
But it still is not working.
Delete first the existing storage link in public.
after, re-run (in app path)
php artisan storage:link
I have fixed the image issue by editing config/filesystems.php
change the 'public' => root & url value as per your project.. i think it will fix it..
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('../../public_html/images'),
'url' => env('APP_URL').'/images',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
Having struggled with this symbolic link, here is the procedure:
Once the installation is done on the production server:
cd public
rm storage
Go to the admin panel of Voyager and click on Fix It. Do not use the PHP command artisan storage:link.
Everything works now.

Categories