orkhanahmadov/laravel-zip-validator
Composer 安装命令:
composer require orkhanahmadov/laravel-zip-validator
包简介
Laravel ZIP file content validator
README 文档
README
Custom Laravel validation rule for checking ZIP file content.
Requirements
- Laravel 9 or higher
- PHP 8.0 or higher with
zipextension enabled
Installation
You can install the package via composer:
composer require orkhanahmadov/laravel-zip-validator
Usage
Use ZipContent rule with list of required files.
use Orkhanahmadov\ZipValidator\Rules\ZipContent; public function rules() { return [ 'file' => [ 'required', 'file', 'mimes:zip', new ZipContent('thumb.jpg', 'assets/logo.png'), ], ]; }
Pass list of required files/folders to the constructor of the validator.
You can pass files as different constructor arguments or as array. If files are nested inside folders, pass relative path to file.
Validator will fail if any of the passed files does not exist in ZIP archive.
Validating maximum file size
Validator also allows checking maximum size of each file inside ZIP archive.
Simply pass file name as array key and maximum size as value:
new ZipContent(['thumb.jpg' => 100000]);
Validator in above example will look for thumb.jpg file with maximum size of 100000 bytes (100KB).
You can also mix multiple files with name-only or name+size validation:
new ZipContent(['thumb.jpg' => 100000, 'logo.png']);
Multiple files with "OR" validation
You can also pass multiple files with | symbol, if any of them exist in ZIP file validator will succeed.
new ZipContent('thumb.jpg|thumb.png|thumb.svg');
Validator in above example will look if thumb.jpg or thumb.png or thumb.svg file exists in ZIP.
Of course, you can also validate file size with "OR" validation:
new ZipContent(['thumb.jpg|thumb.png' => 100000]);
Above example will look if thumb.jpg or thumb.png file exists in ZIP and its file size is not bigger than 100000 bytes (100KB).
Important to keep in mind that when using "OR" validation with additional file size validation, validator will compare file size with the first matching element in ZIP archive.
Rejecting empty files
By default, validator only checks if file with given name exists, it will return true even if file with matching name is empty (has size of 0 bytes).
You can pass array of files as first argument and
false as second argument to constructor if you want validator to reject files with 0 bytes.
new ZipContent(['thumb.jpg', 'style.css'], false);
Wildcard filename matching
Additionally, you can use wildcard filename matching with * symbol.
new ZipContent('*.jpg');
This will return true if Zip archive contains any file with .jpg extension.
Filename matching is using fnmatch function. You can use any of its patterns.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email ahmadov90@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
orkhanahmadov/laravel-zip-validator 适用场景与选型建议
orkhanahmadov/laravel-zip-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.91k 次下载、GitHub Stars 达 124, 最近一次更新时间为 2020 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「validation」 「laravel」 「zip」 「orkhanahmadov」 「zip validation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 orkhanahmadov/laravel-zip-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 orkhanahmadov/laravel-zip-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 orkhanahmadov/laravel-zip-validator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Allow packages to be installed from a repository or tarball bundle that have multiple packages in the sub-folders
Iteration tools for PHP
Adds request-parameter validation to the SLIM 3.x PHP framework
Convert and operate with FIPS codes for states, counties, etc.
A jQuery augmented PHP library for creating and validating HTML forms
Smart compressed files extractor
统计信息
- 总下载量: 24.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 124
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-10