zfegg/attachment-handler

附件上传组件

0.1.2 2024-07-27 18:15 UTC

This package is auto-updated.

Last update: 2024-11-27 18:58:31 UTC


README

GitHub Actions: Run tests Coverage Status Latest Stable Version

附件上传处理器

安装 / 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'
    ]
]