首页 > 解决方案 > 存储:链接在托管 cPanel 上不起作用

问题描述

我已经创建了一个存储链接,php artisan storage:link它在localhost上运行良好,但是,当我在共享主机上部署我的项目时,它不会呈现任何图像。这是我的托管目录结构:

- 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

图像上传没有任何问题,但是当我尝试渲染它们时它们不会渲染,而它们在本地主机上被渲染得非常好。我认为符号链接不起作用。我怎样才能让它工作?

Ps:我在 cPanel 上没有 CLI 的任何访问权限。

标签: laravelstoragehostingcpanellaravel-storage

解决方案


您可以使用 PHP 和 Laravel 辅助方法来做同样的事情,只需运行一次此代码(例如,将其添加到您的控制器并调用一次)以手动创建存储链接:

use Illuminate\Support\Facades\File;

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

推荐阅读