Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

setAllowedMaxFileSize() on SimpleImageField

Go to End

2 Posts   1205 Views


Community Member, 51 Posts

13 November 2010 at 12:22pm

Edited: 13/11/2010 12:23pm

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));


Community Member, 51 Posts

14 November 2010 at 2:38am


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->sessionMessage("Your image is too big!", "alert");