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.

Forum Module /

Discuss the Forum Module.

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

restricting the size of attachments in forum


Go to End
Reply


872 Views

Avatar
Arbee

Community Member, 21 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.