图片上传
本地上传
先添加存储配置,config/filesystems.php 添加一项disk:
'disks' => [
... ,
'admin' => [
'driver' => 'local',
'root' => public_path('uploads'),
'visibility' => 'public',
'url' => env('APP_URL').'/uploads',
],
],
设置上传的路径为 public/uploads(public_path('uploads'))
。
然后选择上传的disk,打开config/admin.php
找到:
'upload' => [
'disk' => 'admin',
'directory' => [
'image' => 'images',
'file' => 'files',
]
],
将disk设置为上面添加的admin,directory.image和directory.file分别为用$form->image($column)和$form->file($column)上传的图片和文件的上传目录。
云端上传
如果需要上传到云存储,需要安装对应laravel storage的适配器,拿七牛云存储举例
首先安装 zgldh/qiniu-laravel-storage
同样配置好disk,在config/filesystems.php 添加一项:
'disks' => [
... ,
'qiniu' => [
'driver' => 'qiniu',
'domains' => [
'default' => 'xxxxx.com1.z0.glb.clouddn.com', //你的七牛域名
'https' => 'dn-yourdomain.qbox.me', //你的HTTPS域名
'custom' => 'static.abc.com', //你的自定义域名
],
'access_key'=> '', //AccessKey
'secret_key'=> '', //SecretKey
'bucket' => '', //Bucket名字
'notify_url'=> '', //持久化处理回调地址
'url' => 'http://of8kfibjo.bkt.clouddn.com/', // 填写文件访问根url
],
],
然后修改laravel-admin的上传配置,打开config/admin.php找到:
'upload' => [
'disk' => 'qiniu',
'directory' => [
'image' => 'image',
'file' => 'file',
],
],
disk选择上面配置的qiniu。
云存储适配器 下面是国内常用云存储的Laravel适配器,参考文档配置
- 阿里云 https://github.com/jacobcyl/Aliyun-oss-storage
- 腾讯云 https://github.com/freyo/flysystem-qcloud-cos-v5
- 七牛 https://github.com/overtrue/laravel-filesystem-qiniu
- 七牛 https://github.com/zgldh/qiniu-laravel-storage
- 又拍云 https://github.com/JellyBool/flysystem-upyun
- 青云 https://github.com/geXingW/laravel-qingstor-storage
- UCloud https://github.com/xujif/ucloud-ufile-storage