【问题标题】:php artisan storage:link on shared Hosting is not showing imagesphp artisan storage:共享主机上的链接未显示图像
【发布时间】:2020-10-18 09:40:38
【问题描述】:

我一直在开发一个 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,但图像仍然损坏。

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', [] );
});

感谢您的帮助。

【问题讨论】:

    标签: laravel symlink laravel-storage


    【解决方案1】:
        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 时都需要这样做!

    【讨论】:

    • 您需要将删除文件夹的标志添加到例如rm -fr storage,这将导致 Please provide a valid cache path 错误。
    猜你喜欢
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    相关资源
    最近更新 更多