Reputation: 73
I use the putFileAs method on the Storage facade to upload my photos.
$gallery = $request->file('feature_image');
Storage::putFileAs(
'just_for_test_putfileas', $gallery, time().'.'. $request->file('feature_image')->getClientOriginalExtension()
);
it works great and default putFileAs dir is "storage/app" and will put my file in this direction "storage/app/just_for_test_putfileas"
when I use ../ in dir to put the file in some other direction it cause an error "whoops, it seems there is something wrong" this block of code cause error
$gallery = $request->file('feature_image');
Storage::putFileAs(
'../just_for_test_putfileas', $gallery, time().'.'. $request->file('feature_image')->getClientOriginalExtension()
);
Upvotes: 3
Views: 12389
Reputation: 16333
When you use the Storage
facade without specifying a disk, it will use the default disk which is usually the local
disk. This disk is rooted/jailed to the /storage/app/ directory and you cannot escape it.
See your settings in config/filesystem.php:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
If you want to be able to read and write files using Laravel's filesystem functionality to a different folder, you can create a new disk and jail it to another location:
'disks' => [
'my-disk' => [
'driver' => 'local',
'root' => storage_path(),
],
In my example above I have created a new disk jailed to the /storage/ path, which is the path above /storage/app/. You can then use your disk with the Storage
facade like this:
Storage::disk('my-disk')->putFileAs(...);
Upvotes: 14