【问题标题】:Opencart deleting image/cache does nothingOpencart删除图像/缓存什么都不做
【发布时间】:2017-06-08 03:25:48
【问题描述】:

我在使用 Opencart 缓存图像时遇到了一些严重问题。我有一个与 Opencart 同步信息(产品、类别)等的软件。

每当我更新已有图像的产品时,我只需替换(在 FTP 中)图像 - 因为它具有相同的描述(id)。

--- First upload product ---
image/myfolder/id_of_image.jpg

--- Second upload product (update) ---
image/myfolder/id_of_image.jpg -> It is replaced

--- Third upload product (update) ---
image/myfolder/id_of_image.jpg -> It is replaced

等等。发生的情况是 Opencart 继续使用第一次同步中设置的相同图像。这不是浏览器问题,因为不同的浏览器显示相同的第一个图像同步。

Opencart 会在打开产品页面时强制调整图像大小,并根据图像大小创建一个新的内部文件,例如 19301-500x445.jpg只有在大小图像不存在时才会发生这种情况

// Within the file catalog/model/tool/image

$image_old = $filename;
$image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '.' . $extension;

if (!is_file(DIR_IMAGE . $image_new) || (filectime(DIR_IMAGE . $image_old) > filectime(DIR_IMAGE . $image_new))) 
{ 
}

我可以通过在文件名中设置time() 来设法避免缓存问题,但这样opencart 会不断创建不必要的新图像。

$image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '-' . time() . '.' . $extension;

删除image/cache/myfolder/* 没有任何影响。

【问题讨论】:

    标签: php image caching opencart


    【解决方案1】:

    已解决。

    将我的函数更改为以下内容:

    if(filectime(DIR_IMAGE . $image_old) > filectime(DIR_IMAGE . $image_new) || !file_exists(DIR_IMAGE . $image_new))
    {   
        if(file_exists(DIR_IMAGE . $image_new))
            $image_new  = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '-' . time() . '.' . $extension;
    }
    

    这样,它只生成一次图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-21
      • 2014-10-20
      • 2013-01-14
      • 1970-01-01
      • 2015-04-13
      • 2013-07-14
      • 2011-03-01
      • 1970-01-01
      相关资源
      最近更新 更多