voyager project is installed on a subdomaine. https://sub.domainname.com/ ,
There is no problem in uploading images in local and I can show them But when i try it on hosting, the pictures appear broken, no matter what i did
APP URL
APP_URL=https://sub.domainname.com
Config/fileSystems
'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_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'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
],
],
after uploading an image its image on the media menu
enter image description here
Did you publish the storage folder link? php artisan storage:link
Sorry, but is all your code inside the public_html folder? I mean, is there all including routes, storage, app, etc.?
This may affect the way your application considers where is the public folder. So you can open Tinker or add a log to see if the public_path() function is returning the correct path. If not, then you should instruct your application to redirect the path to the right folder or change the structure of your project to one more convenient/secure.
Also is the one from the example the subdomain? As it looks like a main domain.
PS: I don't know much about the cons, but most people doesn't recommend exposing paths here, like your project's domain or structure, as you don't know what can people do with that information.
Update Question
I'm uploading from my subdomain project to the storage folder in the root directory
this way I created a voyager storage in
'voyager' => [
'driver' => 'local',
'root' => '/home/username/public_html/storage/app/public',
'url' => 'https://website.com/storage',
'visibility' => 'public',
]
In my config/voyager.php file, I gave the disk I created custom.
'storage' => [
'disk' => 'voyager',
],
In this way, I can send images to the root directory of the project under public_html, but my images are still not visible on voyager.
The path of the images looks like this;
https://website.com/storage/works/July2022/5w9ONuhB1VgQFLj9hGJH.png
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.
I'm messed with the paths to get UniSharp / laravel-filemanager working on the server. In local mode it works perfectly but now I'm making the change of routes for production in online mode and I am not clear at all.
The problem is that it loads the images but they are not displayed either on the page or in the filemanager itself. In filemanager, I can see a red square with a cross (as error).
Let's see if anyone knows how to write the correct routes. I have tried many things but I'm messed.
The server files scaffolding:
server_files
my_laravel_app
public_html
another_files
The config filesystem.php file in Laravel:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('public_html'),
'url' => env('APP_URL').'/storage',
'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'),
],
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
I have, default uploading path in filemanager's lfm.php:
'disk' => 'public',
In case it helps something, this is my index.php ubicated at public_html:
if (file_exists(__DIR__.'/../my_app_laravel/storage/framework/maintenance.php')) {
require __DIR__.'/../my_app_laravel/storage/framework/maintenance.php';
}
require __DIR__.'/../my_app_laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../my_app_laravel/bootstrap/app.php';
And this is ServiceProviders.php
public function register()
{
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
}
How should be the correct path in filesystem to allow filemanager can access to images and display them?
Note: the public_html folder has the symbolic link as you can see at filesystem.php.
I have checking routes and I solved temporary:
I changed:
'public' => [
'driver' => 'local',
/* this */ 'root' => storage_path('app/public'),
/* this */ 'url' => env('APP_URL').'/storage/app/public',
'visibility' => 'public',
],
And now I can upload and see the images in file manager and inside the web app. But now the problem is that users can visit the image url and see the private route of the folder:
http//mi_lar_app/storage/app/public/photos/31/art_1/fig_1.0.png
Some help????
If you have similar problems, the procedure I do in this case was to create a symbolic link with routes (I created a php file because I haven't access to SSH on my server):
<?php
/*__DIR__ is the directory file, where you save this file.php */
$mytargetDIR = __DIR__.'/../mi_lar_app/storage';
$mylinkDIR = __DIR__.'/storage';
symlink($mytargetDIR,$mylinkDIR);
echo 'Todo ok/ Symlink process successfully completed';
?>
And important, remember clean cache and routes every changes. If you don't have SSH access:
<?php
Artisan::call('cache:clear');
Artisan::call('config:cache');
Artisan::call('route:cache');
Artisan::call('view:clear');
return 'Todo limpio/All is cleaned';
?>
And next this little explanation, some help to me?? :)
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 have transferred website from local to web server, mean while i changed some scenarios.
1- I have changed folder structure and moved public folder files on root.
2- Image files are being uploaded into store folder while symbolic storage folder is moved on root also.
But after moving public folder files on root images not working. while uploaded images are being stored into main storage folder. but not linked with symbolic storage folder. so help me how can i attach again both storage folders.
Storage folder related code into config/filesystem is shown below:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app/pulic/images/'),
],
'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'),
],
],
main storage folder path is:
Root/Laravel_files/storage/app/public/images
while symbolic storage folder address is:
Root/storage/images
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');