We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



9.4k
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:

https://docs.phalcon.io/en/latest/api/Phalcon_Http_Request_File.html

Hope it helps.