onix-systems-php / hyperf-file-upload
用于维护文件上传和分配的扩展
v1.2.1
2024-02-29 08:59 UTC
Requires
- php: >=8.1
- ext-fileinfo: *
- ext-gd: *
- ext-json: *
- hyperf/config: ^3.1
- hyperf/contract: ^3.1
- hyperf/database: ^3.1
- hyperf/db-connection: ^3.1
- hyperf/filesystem: ^3.1
- hyperf/guzzle: ^3.1
- hyperf/translation: ^3.1
- hyperf/validation: ^3.1
- intervention/image: ^2.7
- league/flysystem: ^2.0|^3.0
- onix-systems-php/hyperf-actions-log: ^1.2
- onix-systems-php/hyperf-core: >=1.2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: >=7.0
- swoole/ide-helper: ^4.5|^5.0
Suggests
- swow/swow: Required to create swow components.
README
包含以下类
- 模型
- File;
- FileRelations 特性。
- 仓库
- FileRepository.
- 服务
- AddExternalFileService;
- AddFileService;
- ClearUnusedDeletedFilesService;
- DownloadFileService.
安装
composer require onix-systems-php/hyperf-file-upload
发布配置和数据库迁移
php bin/hyperf.php vendor:publish onix-systems-php/hyperf-file-upload
将文件上传配置填入 file_upload
配置,按照现有示例操作。
添加 $fileRelations
配置和 FileRelations
特性到您想要分配文件的模型中
use FileRelations; public $fileRelations = [ 'avatar' => [ 'limit' => 1, 'required' => false, 'mimeTypes' => [image/png', 'image/jpg', 'image/jpeg', 'image/bmp'], 'presets' => [ '150x150' => ['fit' => [150, 150]], '250x250' => ['fit' => [250, 250]], ], ], 'documents' => [ 'limit' => null, 'required' => false, 'mimeTypes' => ['application/pdf'], ], ];
您可能需要在 FileRelations
特性中重新定义的方法
getAuth
: 此方法应返回活动用户processFileActions
: 如果您在配置中定义了新的额外操作,您需要在此方法中定义操作的登录