in my shared hosting (without SSH) my laravel installation save file from form only in storage/app/public/namefolder but not in storage/namefolder and this causes the files not to be displayed.
How can I solve it? Is there anything I need to change in the filesystem of the online site on shared hosting? or do I have to do anything else?
thanks a lot
this is where i store my file
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
i think your problem that you can not make the symlink command for storage as you do not has a SSH
php artisan storage:link
this command will create a symlink - a shortcut- to storage directory inside public directory,
there is several ways to apply this command with out accessing server via SSH
Route::get('artisan-command', function(){
Artisan::call('storage:link');
});
or you can call it with in a class
after you run the command every thing will work just fine , and no need to change config more than usual stuff.
Related
This is in Nova but I think the issue is with how I've setup the filesystem. But just for the full context: I use the Nova Image field to upload an image.
In my config/filesystems:
'blog' => [
'driver' => 'local',
'root' => storage_path('app/public/blog'),
'url' => env('APP_URL').'/storage/blog',
'visibility' => 'public',
],
The file is uploaded correctly and a preview shows in Nova, both locally and on production. The preview uses the URL example.com/storage/blog/filename.jpg.
On the front-end I use asset('blog/'.$post->image) to display the image. The URL generated is example.com/blog/filename.jpg.
The weird thing is that this last URL works locally, but not on a production server (gives a 404). Does this have to do with folder/file permissions?
I have ran php artisan storage:link and on the server I can actually see the file both in app/public/blog and in public/storage/blog.
I have this filesystem config for my folder:
'apks' => [
'driver' => 'local',
'root' => storage_path('app/public/apks'),
'url' => env('APP_URL') . '/storage/apks',
'visibility' => 'public',
]
Here are app apks saved.
I need to return the URL to the file (NOT THE FILE ITSELF).
The android APK manager will then download and install the file by using the URL.
The URL is created by calling:
Storage::disk('apks')->url($result->filename)
It works, the URL looks like this:
https://www.example.com/storage/apks/app-debug.apk
BUT it can not download the file.
Also if I use this URL in the browser I get a 404 error
I would have expected that the file will be downloaded.
You need to generate a symlink for access publicly from the storage folder.
Here you can able to run below command in the composer:
php artisan storage:link
Now you can access:
https://www.example.com/storage/apks/yourfile.xyz
i have two project in laravel 5.8.
First in sub1.domain.com
Second in sub2.domain.com
With sub2 i save images and files.
I need to view the image and files from sub2 and sub1.
Where is the best directory store for sharing the image and files ?
I have a shared hosting.
Thanks.
UPDATE - SOLVED
I have changed my filestystem config in this mode:
'public' => [
'driver' => 'local',
// 'root' => public_path() . '/uploads',
'root' => '/home/xxx/www',
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Now the file is stored in "public_html" of my "website.com" on my hosting for every subdomain.
Thanks everybody.
The docs state
The public disk is intended for files that are going to be publicly
accessible. By default, the public disk uses the local driver and
stores these files in storage/app/public. To make them accessible from
the web, you should create a symbolic link from public/storage to
storage/app/public
Assuming all your images & files will be publicly accessible, follow those instructions.
Then, instead of using asset('storage/file.txt') to print out the publicly accessible url, you could use a value from your .env file to get the path, which would be something like "https://sub2.domain.com/images/" and then just append your file name.
Or write a custom helper method that allows you to specify the subdomain, something like custom_asset('storage/file.txt', 'sub2')
you can upload in public folder as symbolic link is hard hard to make cpanel
modify ur
filesystems.php
in
'public' => [
'driver' => 'local',
'root' => public_path('app/public/uploads'),
'url' => env('APP_URL').'/uploads',
'visibility' => 'public',
],
in above linke
ur upload path will be
public/uploads
and
\Storage::url('example.png') to get full image url
I have uploaded a voyager admin panel in my cPanel.
It gives error Missing storage symlinkand images are not shown of new added item.
Suppose I want to add a new user. All information is shown of new user accept user avatar.
In locally error is easily fixed by running the cmd php artisan storage:link.
But in live server how to fixed this error ?
I have already change the path of storage driver in config/filesystems.php. Change the path from storage_path() to public_path()
'public' => [
'driver' => 'local',
'root' => public_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
FIXED !!
Delete public/storage folder and run the command in cmd
php artisan storage:link
It is a path related problem. I have changed the App_url in my .env file. Now it's successfully showing the image.
I had the same issue. It happened because the file structure or something changed from the original Laravel setup. For me, I switched from using Artisan to vagrant.
I resolved by logging into vagrant and removing the original symlink:
rm -rf /home/vagrant/code/public/storage
I went ahead and created the new symlink but you should now be able to click the Fix link in Voyager admin to create the new one.
ln -s /home/vagrant/code/storage/app/public /home/vagrant/code/public/storage
You need to change the storage path into de filesystems.php file
to:
'public' => [
'driver' => 'local',
'root' => storage_path('./../../public_html/storage'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
this works for me !
cd public_html
ln -sr ../storage/app/public storage
I've fixed this by deleting the public/storage link and folder and then create again the folder and then:
php artisan storage:link
EDIT:
I also had to set this configuration in the filesystems.php
'public' => [
'driver' => 'local',
'root' => public_path('storage'),
'url' => env('APP_URL').'storage',
'visibility' => 'public',
],
I've fixed this by most easy way:
remove storage folder from public directory, then hit fix button from
admin area
I've created a sub folder for each user in local storage disk with this command:
if(! Storage::disk('public')->has("users/".$username."_".Auth::user()->id)){
Storage::makeDirectory("public/users/".$username."_".Auth::user()->id);
and it works!
So now when i save a file, all goes in the user's folder, that is in:
storage/app/public/users/userX
storage/app/public/users/userY
etc.
Then I build a sim link with the command: php aritsan storage:link
And it works.
But when im trying to serve the files i've allways nothing to serve!
If im using code like:
Storage::url("$urlToFile");
where $urlToFile contains something like "public/users/userX/file.png"
it gives me back:
/storage/users/userX/file.png
and I cant use it even if i put function like assett() in front!
how can i solve it?
Thanks in advance!
You have to set url in config/filesystem.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
You can do it by Storage::disk('public')->get($url);
According to the docs, you should access your images like: asset('storage/users/userX/file.png');, not public/users/userX/file.png as you are using.