Laravel Storage returns: mkdir(): File exists - php

When I'll try to check if a file exists in Laravel 5.1 I am always getting this error:
ErrorException in Local.php line 95:
mkdir(): File exists
I don't know what could here be wrong, I want to check if a file exists or not with:
$exists = Storage::disk('images')->has('filename.jpg');
dd($exists);
Disk "images":
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path().'/app',
],
'images' => [
'driver' => 'local',
'root' => storage_path().'/app/images',
],
Any ideas?

If I were you, I would try fresh installation to verify if you experience the same problem on fresh installation:
composer create-project laravel/laravel testfiles 5.1.*
add into filesystems.php in disks:
'images' => [
'driver' => 'local',
'root' => storage_path().'/app/images',
],
Modify in Http/routes.php file so root path looks like this:
Route::get('/', function () {
$exists = Storage::disk('images')->has('filename.jpg');
dd($exists);
return view('welcome');
});
Of course you need to also set up domain for this sample project.
On mine PC I'm getting false without any error.
If you have this error on fresh install, well, it's a problem, if not, maybe you could also publish your composer.json and composer.lock files to verify it on exact libarries you are using?

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')

why laravel 5.6 returns file does not exist error?

I putted file on project-dir/client_secret_1***.apps.googleusercontent.com.json and then added variable into env file.
GOOGLE_PLAY_CREDENTIAL=http://local.project-dir/client_secret_1***.apps.googleusercontent.com.json
and then in config/services.php
return [
'google_play' => [
'credential' => env('GOOGLE_PLAY_CREDENTIAL'),
],
];
So now when I use it as like below
$client->setAuthConfig(config('services.google_play.credential'));
it is returning error which is
"file "http://local.project-dir/client_secret_1***.apps.googleusercontent.com.json" does not exist"
Can someone kindly guide me, where I am wrong so that I can fix the issue. I would like to appreciate.
Thanks
Use Laravel Storage.
Edit config/filesystems.php to create new disk:
'services' => [
'driver' => 'local',
'root' => storage_path('app/services'),
],
// ...
Put your .json file into %your_project_root%/storage/app/services/
Edit .env file:
GOOGLE_PLAY_CREDENTIAL=client_secret_1***.apps.googleusercontent.com.json
Change setAuthConfig param:
$client->setAuthConfig(Storage::disk('services')->get(config('services.google_play.credential')));
Test your storage using Tinker in console:
php artisan tinker
Storage::disk('services')->get(config('services.google_play.credential'));

Adding Custom path for storage in filesystems.php Laravel

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

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

Categories