Hi, I send some files from client (Vue Js) to Api (Phalcon) by multipart/form-data header and when I'm using file validation I'm getting "Field files must not be empty" error.
What is wrong ?
My sent data: files[0]: (binary) files[1]: (binary)
My code in phalcon:
<?php
$validation = new Validation();
$fileValidator = new File([
"maxSize" => "2M",
"messageSize" => ":field exceeds the max filesize (:max)",
"allowedTypes" => [
"image/png",
],
"messageType" => "Allowed file types are :types",
"maxResolution" => "800x600",
"messageMaxResolution" => "Max resolution of :field is :max",
]);
$validation->add('files', $fileValidator);
$messages = $validation->validate($_FILES);
$data['ok'] = false;
if (count($messages)) {
foreach ($messages as $message) {
$data['message'][] = $message->getMessage();
}
return $this->setResponse(400, $data);
}
output of $_FILES by var_dump:
array(1) { ["files"]=> array(5) { ["name"]=> array(2) { [0]=> string(7) "158.jpg" [1]=> string(12) "100_1237.JPG" } ["type"]=> array(2) { [0]=> string(10) "image/jpeg" [1]=> string(10) "image/jpeg" } ["tmp_name"]=> array(2) { [0]=> string(24) "E:\xampp\tmp\php4D63.tmp" [1]=> string(24) "E:\xampp\tmp\php4D93.tmp" } ["error"]=> array(2) { [0]=> int(0) [1]=> int(0) } ["size"]=> array(2) { [0]=> int(1099386) [1]=> int(1283710) } } }