【问题标题】:Disk [public] does not have a configured driver. in laravel image upload磁盘 [public] 没有配置的驱动程序。在 laravel 图片上传
【发布时间】:2020-10-01 08:42:06
【问题描述】:

我正在尝试将文件上传到最近工作的公用文件夹,但现在显示以下错误:

磁盘 [public] 没有配置驱动程序。

我尝试在 config/filesystems.php 中检查已配置的驱动程序,但是它已经在那里设置了。我不知道问题可能出在哪里。

上传代码:

public function upload(ProductImageRequest $request, Product $product)
{
    $image = $request->file('file');
    $dbPath = $image->storePublicly('uploads/catalog/'.$product->id, 'public');

    if ($product->images === null || $product->images->count() === 0) {
        $imageModel = $product->images()->create(
            ['path' => $dbPath,
            'is_main_image' => 1, ]
        );
    } else {
        $imageModel = $product->images()->create(['path' => $dbPath]);
    }

    return response()->json(['image' => $imageModel]);
}

config/filesystems.php 中的代码

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

【问题讨论】:

  • 尝试 php artisan config:clear
  • 试了多次还是问题依旧
  • 你是如何解决你的问题的??

标签: php laravel file-upload public laravel-filesystem


【解决方案1】:

我使用此代码移动图片并存储它的名称,您可能想试一试

//get icon path and moving it
$iconName = time().'.'.request()->icon->getClientOriginalExtension();
$icon_path = '/category/icon/'.$iconName;
request()->icon->move(public_path('/category/icon/'), $iconName);  
$category->icon = $icon_path;

我通常会移动图像,然后将其路径存储在 db 中,这就是我的代码显示的内容,您可以根据需要对其进行编辑

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    • 2011-04-26
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    相关资源
    最近更新 更多