【问题标题】:how to upload images in public_html not in project file in laravel?如何在 public_html 中上传图片而不是在 laravel 的项目文件中?
【发布时间】:2021-04-10 22:31:24
【问题描述】:

我将我的 Laravel 应用程序上传到 C-panel,我的公共内容在 public_html 中,我将 public 上的 index.php 更改为:

require __DIR__.'/../thermotajhiz/vendor/autoload.php';

$app = require_once __DIR__.'/../thermotajhiz/bootstrap/app.php';

以及主根目录中名为 thermotajhiz

的其他文件

一切正常,但是当我想上传图片时,不是上传到 public_html,而是在 public_html 之外的 thermotajhiz 文件中创建一个具有公共名称的文件

我该如何解决这个问题?

我正在使用这个插件来上传文件:

alexusmai/laravel-file-manager

【问题讨论】:

标签: laravel file-upload laravel-7


【解决方案1】:

config/filesystems.php中设置成这样

// Filesystem Disks
'disks' => [
    'public' => [
        'driver' => 'local',
        'root' => '../public_html',
        'url' => env('APP_URL'),
        'visibility' => 'public',
    ],

],

如果不起作用,请尝试将../public_html 更改为../../public_html/home/yourcpanelusername/public_html

并确保在您的config/file-manager.php 中设置:

'leftDisk'  => 'public',

【讨论】:

  • cpanel 'root' => /, 目录不公开,因此无法使用
  • @KamleshPaul ,我错了编辑字段,我更新了答案。谢谢
【解决方案2】:

我把这段代码放到 index.php 中,而不是 AppServiceProvider 中的 register 方法,它的工作原理:

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

在这段代码之后:

$app = require_once __DIR__.'/../thermotajhiz/bootstrap/app.php';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 2022-11-20
    • 2021-03-23
    • 1970-01-01
    • 2018-06-29
    相关资源
    最近更新 更多