php - Phalcon 4 validation multipart/form-data multiple
one text
Is it possible to configure the file validator of Phalcon4, where it can validate multiple uploaded files?
I cannot find any documentation about multiple files upload, just file upload with different form fields: https://docs.phalcon.io/4.0/en/api/phalcon_validation#validation-validator-file
I can validate files which are uploaded one by one, but I need the form to handle multiple uploaded files at once.
Here is my code:
HTML
<input type="file" id="formFile" name="media[]" multiple>
Controller
$validation = new FileUploadValidation();
$validation->validate($_FILES);
FileUploadValidation.php
<?php
namespace App\Validator;
use Phalcon\Validation;
use Phalcon\Validation\Validator\File as FileValidator;
class FileUploadValidation extends Validation
{
public function initialize()
{
$this->add(
['media'],
new FileValidator(
[
"maxSize" => "2M",
"messageSize" => ":field exceeds the max file size (:size)",
"allowedTypes" => [
"image/jpeg",
"image/png",
],
"messageType" => "Allowed file types are :types",
]
)
);
}
}
Source