Skip to content

OpenCart do not show images | CageFS

There is site on Hosting with CageFS on CloudLinux (https://docs.cloudlinux.com/index.html?cagefs.html) OpenCart (v.??)

Problem: don't show images anywhere: main page, catalog (allproduct) page. Tag src of image is empty. No error or warning about it in php_error.log

Site place on filesystem: /home7/nickname/public_html/

In file ./catalog/model/tool/image.php is code:

class ModelToolImage extends Model {
        public function resize($filename, $width, $height) {
...
 if (!is_file(DIR_IMAGE . $filename)  ||  substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) {
                        return;
                }

In site's config.php set:

//
define('DIR_IMAGE', '/home7/nickname/public_html/image/');
//

Reason: When PHP execute realpath(DIR_IMAGE . $filename) will get:

/home/nickname/public_html/image/

And condition

 substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE

will be TRUE always!

Solution 1:

In site's config.php set all path without digits:

//
define('DIR_IMAGE', '/home/nickname/public_html/image/');
//

Solution 2:

Comment condition with function realpath in ./catalog/model/tool/image.php And add Errlog to your log system!

class ModelToolImage extends Model {
        public function resize($filename, $width, $height) {
//...
 if (!is_file(DIR_IMAGE . $filename)   {

// incorrect condition on cageFS
// ||  substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) {
                        wlog('ERROR. File not found: '.DIR_IMAGE . $filename);
                        return;
                }

Updated 2019-02-19:

Vendor update Cagefs logic : https://docs.cloudlinux.com/mounting_users_home_directory_.html