I've a question, how can change filepath in laravel?
this is my code on under.
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
now, when I upload the file, it will saved to /storage/app/public/images
123.com/storage/app/public/images
how can change filepath to /public/storage/images
123.com/public/storage/images
Related
I'm trying to create a Dashboard for a personal project,
I want the storage of the Dashboard to be completely separate from the front end,
I create a new disk in the filesystem.php and this is the details:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'backend' => [
'driver' => 'local',
'root' => storage_path('app/backend'),
'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'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
],
],
after that, I try to store some avatars and it works perfectly,
my problem is when I want to access the files from the view side,
Note that I try the visibility on both public and private
,also
I want to store sensitive files inside it
so I try:
url('/storage/avatars/filename.png'),
storage_path('backend/avatars/filename.png'),
storage::disk('backend')->get('avatars/filename.png'),
but nothing.
What is your question exactly? I assume you are trying to display images on a webpage, but they are not showing up?
This has to do with the visibility of your files. Only files in the storage/app/public directory are available for display. So images that should be visible using a URL, should be stored in that directory.
The best practice here is to upload the image to the Public disk. Make sure to create the symoblic link using php artisan storage:link.
For any other non-public file, you can set-up a Controller to return a download response
Another option is to display content right away in the browser, like a PDF. In that case, you should set the correct Content-Type while returning the response, with the contents of the PDF.
If this did not answer your question, please let me know.
please tell me. My version is Laravel 5.2.
config/filesystems.php configuration:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
If I save the file this way:
Storage::disk('local')->put('token/token.json', json_encode($data));
Will users be able to access it? I just need to keep the token in a safe place so that no one can access it. Thank you in advance for your response
On Laravel 8
file_get_contents(asset('storage/list.json');
Give me:
ErrorException
file_get_contents(http://localhost:8000/storage/list.json): failed to
open stream: HTTP request failed!
But: http://localhost:8000/storage/list.json exist and it is accesible via browser for example.
On my config/filesystem.php iv'e:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'permissions' => [
'file' => [
'public' => 0664,
'private' => 0600,
],
'dir' => [
'public' => 0775,
'private' => 0700,
],
],
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
And ive created the symbolic link with:
php artisan storage:link
command.
I've tried even to add manually file perssion to storage folder as described in the filesystem.php but nothing change.
You should use absolute paths when you want to work with files. file_get_contents() is fine. There are some file wrappers available in laravel but internally they all use file_get_contents().
Try
file_get_contents(public_path(asset('storage/list.json')));
If getting from storage file try
file_get_contents(storage_path('app/assets/list.json'));
See https://laravel.com/docs/5.5/helpers#method-resource-path
I need to display in blade the videos uploaded in storage/videos and i don't know how to do.
For uploading them in storage i put this code in filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'video' => [
'driver' => 'local',
'root' => storage_path(),
'url' => env('APP_URL').'storage/video',
'visibility' => 'public',
],
I tried many combinations for the path but anyone doesnt's work
url/storage/video/VHqPwguZeM6mf4csBTfj.mp4
or
url/storage/VHqPwguZeM6mf4csBTfj.mp4
or
url/video/VHqPwguZeM6mf4csBTfj.mp4
Can anyone help me?
Thanks!
The solution is easy once you have uploaded the video in storage/videos you have to do two steps:
php artisan storage:link
this command links your public folder with storage after that you can find a shortcut of storage folder in your public folder.
2.In your blade file just do this:
I'm trying to store a file in the public folder storage/app/public/ but for some reason Laravel just seems to put it in the private storage/app/ folder.
If I understand correctly I'm supposed to just set the visibility to 'public' but that doesn't seem to change anything:
Storage::put($fileName, file_get_contents($file), 'public');
When I call getVisibility I get public so that seems to work fine:
Storage::getVisibility($fileName); // public
These are the settings in my filesystems.php:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
When you call Storage::put, Laravel will use the default disk which is 'local'.
The local disk stores files at its root: storage_path('app'). The visibility has nothing with where the file should be stored.
You need to choose the public disk which will store the files at its root: storage_path('app/public'),
To do that, you need to tell Laravel which disk to use when uploading the file. Basically change your code to this:
Storage::disk('public')->put($fileName, file_get_contents($file), 'public');