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


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.


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:

Hope it helps.