I wanted to validate the uploaded image with following parameters like size should not be greater than 100KB, file can be of types [jpg,png,gif]. Please help me to write validation rules for this in Slim framework. I'm using Respect validator.
$files = $request->getUploadedFiles();
$validation = $this->validator->validate($request, [
'name' => v::notEmpty(),
'description' => v::notEmpty(),
'logo' => v::size('100KB')->mimetype('image/png,image/png,image/gif')->validate($files['logo']->getClientFilename()),
]);
if ($validation->failed()) {
$errors = $validation->errors;
$print_r($errors);
}
This is how I'm using validation rules. Everything works except logo validation.
You can do something to validate your file size like this
v being the validator you are using
You can do the following to validate the mine types
Using the Respect validatio, this might be useful http://respect.github.io/Validation/docs/validators.html