Laravel Zip Content Validator
Published on by Paul Redmond
Laravel Zip Content Validator by Orkhan Ahmadov is a custom validation rule for checking the contents of an uploaded ZIP file:
use Orkhanahmadov\ZipValidator\Rules\ZipContent; public function rules(){ return [ 'file' => [ 'required', 'file', 'mimes:zip', new ZipContent('thumb.jpg', 'assets/logo.png') ], ];}
In addition to checking the existence of file paths, you can also validate the maximum size of a file. The unit of the value is bytes: 100000
equals 100KB
:
new ZipContent(['thumb.jpg' => 100000, 'logo.png']);
You can also use an “or” style of validation. Here’s an example of “or” validation in tandem with maximum size:
new ZipContent(['thumb.jpg|thumb.png' => 100000]);
Finally, you can reject empty files with false
as a second argument:
new ZipContent(['thumb.jpg', 'style.css'], false);
You can learn more about this package, get full installation instructions, and view the source code on GitHub: laravel-zip-validator.