Jump to:

1030 Posts in 805 Topics by 311 members

Forum Module

SilverStripe Forums » Forum Module » restricting the size of attachments in forum

Discuss the Forum Module.

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

Page: 1
Go to End
Author Topic: 643 Views
  • Arbee
    Avatar
    Community Member
    17 Posts

    restricting the size of attachments in forum Link to this post

    I am trying to reduce the file size of an image uploaded to no more than 200 kb. It does not appear to be working as I can upload larger files. This is what I have:

    if($this->canAttach()) {
             $fileUploadField = new FileField("Attachment", "Attach File (files must be less than 200 kb in size)");
             $f_validator = new Upload_Validator();
             $f_validator->setAllowedExtensions(array('pdf','png','jpg')); // set your extensions here
             $f_validator->setAllowedMaxFileSize( array('*' => 204800) );
             $fileUploadField->setValidator($f_validator);
             $fields->push(
                $fileUploadField
             );
          }

    and this....

    if($this->canAttach()) {
             $fileUploadField = new FileField("Attachment", "Attach File");
             $f_validator = new Upload_Validator();
             $f_validator->setAllowedExtensions(array('pdf','png','jpg')); // set your extensions here
             $f_validator->setAllowedMaxFileSize( array('*' => 204800) );
             $fileUploadField->setValidator($f_validator);
             $fields->insertBefore($fileUploadField, 'CurrentAttachments');
          }

    Where am I going wrong?
    Thanks for your help.

    643 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.