storage:link not working on hosting cPanel

只愿长相守 提交于 2020-12-13 17:55:47

问题


So, I've created a storage link with php artisan storage:link and it's working totally fine on localhost, However when I deploy my project on a shared hosting, it does not show any images. This is my hosting directory structure:

- home2/username
:   + other hosting folders
:   - MyLaravelWebSite
:   :   + other laravel folders
:   :   - storage
:   :   :   - app
:   :   :   :   - public
:   :   :   :   :   -images
:   :   :   :   :   :   * some-image.jpg
:   :   :   :   * gitignore
:   :   :   + framework
:   :   :   + logs
:   - public_html
:   :   + assets
:   :   + storage // symlink
:   :   * index.php

Images are uploading totally fine, but whenever I try to display them they're not showing, while they're displaying absolutely fine on localhost. I think the symbolic link is not working. How can I make it work?

P.s: I don't have any access of CLI on cPanel.


回答1:


You can use PHP and Laravel helper methods to do the same, just run this code once (e.g. add it in your controller and call it once) to create storage link manually:

use Illuminate\Support\Facades\File;

File::link(
    storage_path('app/public'), public_path('storage')
);



回答2:


Update filesystems.php

'public' => [
            'driver' => 'local',
            'root' => public_path() . '/uploads',// upload file in public dir
            'url' => env('APP_URL').'/uploads', // help to get Storage::url() 
            'visibility' => 'public',
        ],

put this in filesystems.php then your all file will be saved in public/uploads folder and to get url this function Storage::disk('public')->url($dbImageUrl); will be work

this is for cpanel if you are not able to create symlink then



来源:https://stackoverflow.com/questions/60036552/storagelink-not-working-on-hosting-cpanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!