zfegg / attachment-handler
附件上传组件
0.1.2
2024-07-27 18:15 UTC
Requires
- php: >=8.0
- ext-json: *
- laminas/laminas-diactoros: ^2.8 | ^3.0
- league/flysystem: ^1.1
- psr/container: ^1.0 | ^2.0
- psr/http-factory: ^1.0
- psr/http-server-handler: ^1.0
- siriusphp/validation: ^3.0
Requires (Dev)
- iidestiny/flysystem-oss: ^2.7
- laminas/laminas-config-aggregator: ^1.13
- laminas/laminas-servicemanager: ^3.10
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^8.0
This package is auto-updated.
Last update: 2024-10-27 18:47:23 UTC
README
附件上传处理器
安装 / Installation
composer require zfegg/attachment-handler
使用 / Usage
在Mezzio中使用
// 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' ] ]