PHP code example of zfegg / attachment-handler

1. Go to this page and download the library: Download zfegg/attachment-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zfegg / attachment-handler example snippets



// 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:[email protected]/uploads
        // sftp://user:[email protected]/uploads
        // memory://temp
        'path' => 'public/uploads'
    ]
]