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:

Forum Module /

Discuss the Forum Module.

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

restricting the size of attachments in forum


Go to End


1367 Views

Avatar
Arbee

Community Member, 31 Posts

12 August 2013 at 5:32am

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.