How can I increase the maximum file name size of attachments in Prestashop 1.7

Viewed 241

On Prestashop 1.7, how can I increase the maximum file name size of attachments?
While naming attachment files in the Back Office, I encounter the following error message.

enter image description here

How can I go around this problem in Prestashop 1.7? I looked up online and found some solutions for Prestashop 1.5 or 1.6, but not for 1.7.

Here are some links that I followed:

Following the above links, I have tried:

  • In the DB, changed the 'name' column's type in the 'ps_attachment_lang' table to 'varchar(128)'.
  • In Attachment.php (/classes/Attachment.php), made sure the size is 128.
'name' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128],
  • In AdminProductsController.php (/controllers/admin/AdminProductsController.php), changed a part of function ajaxProcessAddAttachment(), from
if (!Validate::isGenericName($name)) {
  $_FILES['attachment_file']['error'][] = $this->trans('Invalid name for %s language', [$language['name']], 'Admin.Notifications.Error');
} elseif (Tools::strlen($name) > 32) {
  $_FILES['attachment_file']['error'][] = $this->trans('The name for %1s language is too long (%2d chars max).', [$language['name'], 32], 'Admin.Notifications.Error');
}

to

if (!Validate::isGenericName($name)) {
  $_FILES['attachment_file']['error'][] = $this->trans('Invalid name for %s language', [$language['name']], 'Admin.Notifications.Error');
} elseif (Tools::strlen($name) > 64) {
  $_FILES['attachment_file']['error'][] = $this->trans('The name for %1s language is too long (%2d chars max).', [$language['name'], 64], 'Admin.Notifications.Error');
}

But unfortunately, none of them worked.

Thanks in advance.

1 Answers

This is my own question but I found one solution.

In the AttachmentConstraint.php (in /src/Core/Domain/Attachment/Configuration/AttachmentConstraint.php), find the line

const MAX_NAME_LENGTH = 32;

and change it to whatever number that is lower than your database table can hold:

//const MAX_NAME_LENGTH = 32; 
const MAX_NAME_LENGTH = 128; // this number needs to be lower than `name` column in `ps_attachment_lang` table

This should do the trick, but this solution requires changes in the core file. If there's anyone who knows a way we can achieve this without modifying the core files, please share that.

Related