How to limit the size of the uploaded file

This area is devoted to Magento Form Builder SmartFormer Gold. Please ask questions, report bugs and share ideas here.

How to limit the size of the uploaded file

Postby IToris team » Tue Feb 14, 2012 1:20 pm

For example max size should be no more that 2MB

1. Please add file upload element to the first page of your form.
2. Click it to see its properties. Enter ins name = file_upload
3. Select Tools -> PHP Editor and find $form->doAfterSubmitAction(); line there
4. Insert the following after this line:

Code: Select all
if ($form->page == 1 && isset($form->files['file_upload'])) {
$errors = array();
if (filesize($form->files['file_upload']['tmp_name']) > 2 * 1024 * 1024) {
$errors[] = 'The file size must be less than 2 Mb.';
}
$allowedExtensitons = array('zip', 'jpg', 'tar');
$fileExtension = pathinfo($form->files['file_upload']['name'], PATHINFO_EXTENSION);
if (!in_array($fileExtension, $allowedExtensitons)) {
$errors[] = 'The file extension is not allowed';
}
if (count($errors) > 0) {
$form->error .= implode('<br/>', $errors);
$form->page = 0;
}
}


N.B.
$allowedExtensitons = array('zip', 'jpg', 'tar'); line contains the allowed extensions. Please enter the ones you need there.

5. Save the changes in the editor and close it. Save the form
IToris team
Site Admin
 
Posts: 1355
Joined: Mon Jan 19, 2009 12:33 pm

Return to SmartFormer Gold for Magento

Who is online

Users browsing this forum: No registered users and 1 guest