Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » setAllowedMaxFileSize() on SimpleImageField

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 885 Views
  • neros3
    Avatar
    Community Member
    51 Posts

    setAllowedMaxFileSize() on SimpleImageField Link to this post

    I have a problem with upload of large images.
    If a user via the my custom form uploads an image that is too large for GD to handle it (really high res or really large size (kb)) the upload of the file fails and SS saves a reference to an image that is too big for GD to handle. When ever a page tries to render the image the whole site fails - and keeps failing until i manually remove the reference to the large image in mysql admin.

    I have tried to put size validation on the field - but I still can upload the big files.

    This is what im trying - but it does not work for me. Am i doing it totally wrong or?

    $image = new SimpleImageField("Image");
    $val = new Upload_Validator();
    $val->setAllowedMaxFileSize(array("*" => 200));
    $image->setValidator($val);

  • neros3
    Avatar
    Community Member
    51 Posts

    Re: setAllowedMaxFileSize() on SimpleImageField Link to this post

    Update:

    I still can't get the build-in functionality to work. So for now I will work with this work around.

    I just remove the Image from the Fields list before saving the form data into my object.

    if($data["Image"]["size"] > 1000000){
    $form->Fields()->removeByName("Image");
    $form->sessionMessage("Your image is too big!", "alert");
    }

    $form->saveInto($myClass);

    885 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.