I'm trying to validate a File field (image upload). But I am getting the error:
Fatal error: Class 'Phalcon\Validation\Validator\File' not found in CreateSnapForm.php on line 70
Here are the namespace in CreateSnapForm.php. I've marked line 70:
private function imageField()
{
$image = new File('image');
# Line 70 is the line below ...
$image->addValidator(new FileValidator([
'maxSize' => '2M',
'messageSize' => 'Your image exceeds the max filesize (:max).',
'allowedTypes' => ['image/jpeg', 'image/png'],
'messageType' => 'Your image is not a valid image file.',
]));
$this->add($image);
}
Line 70 is the above.
use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Select;
use Phalcon\Forms\Element\Textarea;
use Phalcon\Forms\Element\Check;
use Phalcon\Forms\Element\Image;
use Phalcon\Forms\Element\File;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Forms\Element\Submit;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\StringLength;
use Phalcon\Validation\Validator\InclusionIn;
use Phalcon\Validation\Validator\Identical;
use Phalcon\Validation\Validator\File as FileValidator;
I have tried hard coding the namespace but I still get the same error.
$image->addValidator(new Phalcon\Validation\Validator\File([
'maxSize' => '2M',
'messageSize' => 'Your image exceeds the max filesize (:max).',
'allowedTypes' => ['image/jpeg', 'image/png'],
'messageType' => 'Your image is not a valid image file.',
]));
Any idea what's happening?