附件上传处理器
composer require zfegg/attachment-handler
// File config/config.php
// Add ConfigProvider
new ConfigAggregator([
Zfegg\AttachmentHandler\ConfigProvider::class,
]);
配置示例:
use Zfegg\AttachmentHandler\AttachmentHandler;
use League\Flysystem\Filesystem;
return [
AttachmentHandler::class => [
'rules' => [
'UploadExtension' => [
'options' => ['allowed' => ['jpg', 'jpeg', 'png', 'gif', 'bmp']],
'messageTemplate' => '文件必须为图片格式 (jpg, jpeg, png, gif, bmp)',
],
'UploadSize' => [
'options' => ['size' => '2M'],
'messageTemplate' => '上传文件必须小于 {max}'
],
],
'storage' => 'images/{date}/{uniqid}.{ext}',
'url' => '/uploads'
],
Filesystem::class => [
// 上传目录,支持 url schema
// ftp://user:pass@127.0.0.1/uploads
// sftp://user:pass@127.0.0.1/uploads
// memory://temp
'path' => 'public/uploads'
]
]