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.

Form Questions /

setAllowedMaxFileSize() on SimpleImageField


Reply


2 Posts   916 Views

Avatar
neros3

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));
$image->setValidator($val);

Avatar
neros3

Community Member, 51 Posts

14 November 2010 at 2:38am

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