laravel-admin如何上传图片以及出现的错误和解决办法

使用laravel-admin上传图片的方法与过程中的问题

1、配置文件config/admin.php

'upload' => [

        // Disk in `config/filesystem.php`.
        'disk' => 'admin',

        // Image and file upload path under the disk above.
        'directory' => [
            'image' => 'images',
            'file'  => 'files',
        ],
    ],

确保这里没问题

2、配置文件config/filesystems.php

/*
    |--------------------------------------------------------------------------
    | Filesystem Disks
    |--------------------------------------------------------------------------
    |
    | Here you may configure as many filesystem "disks" as you wish, and you
    | may even configure multiple disks of the same driver. Defaults have
    | been setup for each driver as an example of the required options.
    |
    | Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace"
    |
    */

    'disks' => [

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

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

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

        'admin' => [
            'driver'     => 'local',
            'root'       => public_path('upload'),
            'visibility' => 'public',
            'url' => env('APP_URL').'/public/upload/',
        ],

    ],

确保这里没问题

3、控制器使用laravel-admin提供的方法

    protected function form()
    {
        $form = new Form(new Brand());


        //$form->number('row', __('Row'));
        $form->text('brand_name', __('Brand name'));
        $form->text('desc', __('Desc'));
//        $form->text('logo', __('Logo'));
        $form->image('logo',__('封面图'))
            ->thumbnail('small', $width = 300, $height = 300)->removable();

        $form->number('sort', __('Sort'))->default(1);

        return $form;
    }

这里上传图片官方文档有很多方法上传,适用于各种上传情况,根据实际情况使用适合自己的上传方法就行,我这里是封面图,所以我就用单图的就行了。
`

4、请求的时候,image报错了,laravel-admin Class ‘Intervention\Image\Facades\Image’ not found,说找不到这个类。

那就安装一下:composer require intervention/image

5、安装image的时候又报错了,composer require intervention/image Your requirements could not be resolved to an installable set of packages.,
说是composer版本什么的问题有网上说解决办法是忽略版本composer install --ignore-platform-reqs 我试了没用。然后我在页面看到报错,说fileinfo扩展没有安装,那就去安装一下扩展

5、继续报错 impossible to create the root directory “/www/wwwroot/hyzt/public/upload”.
impossible to create the root directory "/www/wwwroot/hyzt/public/upload/images"
说没有upload文件夹和images,在指定目录下创建一个upload文件夹,再在upload下面创建images文件夹。

6、config/app.php配置注册一下

'providers' => [
        Intervention\Image\ImageServiceProvider::class,
    ],
'aliases' => [
        'Image' => Intervention\Image\Facades\Image::class,
    ],
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值