php artisan storage:link 在共享主机上不显示图像

php artisan storage:link on shared Hosting is not showing images

我一直在开发 laravel 应用程序,因此出于安全原因,我已将所有 public 文件放在位于 public_html 的基本文件夹中,其他文件已被删除放在public_html/secondBase.

现在当我执行命令:php artisan storage:link 出现以下错误。

 ErrorException

  symlink(): No such file or directory

  at vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:265
    261|      */
    262|     public function link($target, $link)
    263|     {
    264|         if (! windows_os()) {
  > 265|             return symlink($target, $link);
    266|         }
    267|
    268|         $mode = $this->isDirectory($target) ? 'J' : 'H';
    269|

我厌倦了下面的解决方案

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

public function register()
{
    $this->app->bind('path.public', function() {
        return base_path() . '/public_html/base';
    });
}

我试过的第二种方法是制作文件 symlink.php,但图像仍然损坏。

symlink.php

<?php 
symlink('/home/hmm/public_html/secondBase/storage/app/public','/home/hmm/public_html/base/storage');

最后我在出现第一个错误的地方完成了这条路线。

Route::get('/clear', function () {
       
    Artisan::call('route:clear');
    Artisan::call('storage:link', [] );
});

感谢您的帮助。

    Go to /public directory and run:

    rm storage

    Go to Laravel root directory and run:

    php artisan storage:link

当 laravel 项目 moved/copied 到其他文件夹时会出现此问题。

存储 link 仍然存在,因此导致异常错误。 public/storage 文件夹存在并指向错误的位置,需要使用 rm 存储命令将其删除。

之后 运行 php artisan storage:link 在终端中创建存储 link.

每次 laravel moved/copied/部署时都需要这样做!