Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

File element in Form

Hi,

I'd like to create a litte Image Upload with just one Image. I have created a Form Class and in it this code to add a File Element:

public function initialize($entity = null, $options = null) {
    $profilePic = new File('profilePicture', $attributes);
    $profilePic->setLabel("Wähle ein Profilbild");           
}

But how can i set $attributes to set a Validator to allow only .jpg or .png (by extension or by mimetype)?

Thanks for help.



4.2k
Accepted
answer

You may have generated a form with a "file upload" element.

But if you wan to check the real type for the image, you should do it when the file is successfully uploaded....

Check it here:

http://docs.phalconphp.com/en/latest/api/Phalcon%5Http%5Request%5File.html

Hope it helps.