概述
使用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 ‘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配置注册一下
'providers' => [
InterventionImageImageServiceProvider::class,
],
'aliases' => [
'Image' => InterventionImageFacadesImage::class,
],
最后
以上就是灵巧老师为你收集整理的laravel-admin如何上传图片以及出现的错误和解决办法的全部内容,希望文章能够帮你解决laravel-admin如何上传图片以及出现的错误和解决办法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复