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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Forum Module /

Discuss the Forum Module.

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

restricting the size of attachments in forum


Go to End


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