Files manager in PrestaShop - how to add webp support

2022-09-01 image, upload, webp

PrestaShop has a files manager that gives you possibility to upload own files to the /img/cms/ directory. It is useful when you want to upload some pictures to embed them on your website pages. By default this filesmanager support only basic images upload. It is for safety reasons. Accepted by default files extensions are:

  • jpg, jpeg, png, gif, bmp, tiff, svg
  • pdf
  • mov, mpeg, mp4, avi, mpg, wma, flv, webm

Default upload tool also checks the mime type of file (mime - header of file that gives possibility to recognize file type by browser / php server). Accepted mime types are:

  • image/jpeg, image/png, image/gif, image/bmp, image/tiff, image/svg
  • application/pdf,
  • video/mpeg, video/mp4, video/x-msvideo, audio/x-ms-wma, video/x-flv, video/webm

As you can see - there is no webp image format support, both as a file extension .webp and mime type of file: image/webp

 

files manager webp in prestashop

 

How to add support of wepb file to filesmanager in PrestaShop?

To implement support of webp files to prestashop's default files manager it is required to alter core files. Firstly we must apply chagnes to the filesmanager upload php functions, then - also to .htaccess file to make webp files uploaded to /img/cms/ directory visible in front office.

 

Let's start with files manager core file that is responsible for upload process

filesmanager files are located in admin directory, so for each installation of prestashop the admin directory may be different. It's just unique and only you - as a merchant know the path to the admin dir. So in the path below just replace ADMIN_DIR with name of your admin directory.

 

Open file: /admin_dir/filemanager/config/config.php. This file is responsible for upload php scripts configuration. We have to add there support of webp image extension and image/webp mime type of file. 

 

To support .web extension change line:

$ext_img = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'svg'); //Images

to:

$ext_img = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'svg', 'webp'); //Images

 

and line

$ext_file = array('pdf'); //array('doc', 'docx','rtf', 'pdf', 'xls', 'xlsx', 'txt', 'csv','html','xhtml','psd','sql','log','fla','xml','ade','adp','mdb','accdb','ppt','pptx','odt','ots','ott','odb','odg','otp','otg','odf','ods','odp','css','ai'); //Files

to

$ext_file = array('pdf','webp'); //array('doc', 'docx','rtf', 'pdf', 'xls', 'xlsx', 'txt', 'csv','html','xhtml','psd','sql','log','fla','xml','ade','adp','mdb','accdb','ppt','pptx','odt','ots','ott','odb','odg','otp','otg','odf','ods','odp','css','ai'); //Files

 

to support image/webp mime type of file,

change line:

$mime_img = array('image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/tiff', 'image/svg');

to:

$mime_img = array('image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/tiff', 'image/svg', 'image/webp');

That's all. now it's time to accept "webp" files located in /img/cms/ directory in shop's front office

 

.htaccess modification to accept webp files in prestashop's front office

open file: /img/cms/.htaccess

change code from:

# Apache 2.2
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    <Files ~ "(?i)^.*\.(jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico)$">
        Allow from all
    </Files>
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
    Require all denied
    <Files ~ "(?i)^.*\.(jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico)$">
        Require all granted
    </Files>
</IfModule>

to:

# Apache 2.2
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    <Files ~ "(?i)^.*\.(jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico|webp)$">
        Allow from all
    </Files>
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
    Require all denied
    <Files ~ "(?i)^.*\.(jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico|webp)$">
        Require all granted
    </Files>
</IfModule>

 

And that's all. Your files manager tool in shop's back office should allow to upload .webp files and add them (and display!) in shop's front office.

author milos myszczuk
Article by Milosz Myszczuk PrestaShop expert, official PrestaShop community moderator. PHP developer, specialist in relative and spatial databases management, GIS Analyst, CEO & founder of VEKIA interactive agency. Read more about VEKIA company
If you like my articles and want much more valuable tips, feel free to send me donation
1.4 version 1.4.11 1.6 404 addon admin advertise ahref ajax alpha animation api app application authentication back office backup badge banner basics block bootstrap button cache carrier cart catalog category certificate changelog chat class clear client clip cms code colors columns comments configuration contact container content controller cookie counter country coupon css csv currency customer dashboard database debug default delete delivery desktop developer device disable discount displayNav displayTop download dynamic editor effect empty encrypt engine error exchange exclude export facebook faceshop fade fancoupon fancybox fanpage fatal feature feed field file fix fixed font footer free friendly url front ftp full gallery generate gift global godaddy google google+ gray grid groupon header help hide highlight homefeatured homepage hook hosting hover howto htaccess html html5 ID image import include input instagram installation integration iPhone issue javascript jquery kgb knowhow languages law left likebox link list livingsocial loading log login logo loyality mail mailing maintenance manufacturer marketing marquee mcrypt menu meta mobile modification module movie moving multilanguage multiupload must have mysql news newsletter notification number open graph order override page password performance PHP phpmyadmin picture pinterest plugin popup post prestashop prestashop 1.0 prestashop 1.1 prestashop 1.2 prestashop 1.3 prestashop 1.4 prestashop 1.5 price rules problem product profile promotion proslider purifier quantity query quick tip random rates register reinsurance release reporting reset responsive restore results ribbon rich text right sales search security seo service shadow share shipping shop shopmania slider smarty social networks SQL SSL statistics stock store style subcategory superuser support switcher tab tablet tag tax template text theme tinyMCE tips and tricks tpl tracking translations tree trends trigger tumblr tutorial twitter update upgrade upload variables video visits voucher vulnerability web2print wide widget width window wishlist wysiwyg youtube zip zopim