首页 > 解决方案 > php artisan storage:共享主机上的链接未显示图像

问题描述

我一直在开发一个 laravel 应用程序,因此出于安全原因,我将所有公共文件放在位于 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,但图像仍然损坏。

符号链接.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', [] );
});

谢谢你的帮助。

标签: laravelsymlinklaravel-storage

解决方案


    Go to /public directory and run:

    rm storage

    Go to Laravel root directory and run:

    php artisan storage:link

当 laravel 项目被移动/复制到其他文件夹时,就会出现这个问题。

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

之后在终端中运行 php artisan storage:link ,它将创建存储链接。

每次移动/复制/部署 laravel 时都需要这样做!


推荐阅读