我是靠谱客的博主 灵巧老师,这篇文章主要介绍laravel-admin如何上传图片以及出现的错误和解决办法,现在分享给大家,希望可以做个参考。

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

1、配置文件config/admin.php

复制代码
1
2
3
4
5
6
7
8
9
10
11
'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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* |-------------------------------------------------------------------------- | 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提供的方法

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 ‘InterventionImageFacadesImage’ 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配置注册一下

复制代码
1
2
3
4
5
6
7
'providers' => [ InterventionImageImageServiceProvider::class, ], 'aliases' => [ 'Image' => InterventionImageFacadesImage::class, ],

最后

以上就是灵巧老师最近收集整理的关于laravel-admin如何上传图片以及出现的错误和解决办法的全部内容,更多相关laravel-admin如何上传图片以及出现内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部