dongmoyu0336 2017-01-23 15:04
浏览 260
已采纳

Opencart删除图像/缓存什么都不做

I'm having some serious trouble with Opencart cache image. I have a software which synchronizes the information (products, categories) etc with Opencart.

Whenever I update a product which has already an image, I just replace (in the FTP) the image - since it has the same description (the 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

And so on. What happens is that Opencart continues with the same image set in the first sync. This is not a browser issue since different browsers shows the same first image sync.

Opencart forces the image to resize whenever opening the product page, and creates a new internal file like 19301-500x445.jpg, depending on the image size. This only happens if the sized image doesn't exists already!

// 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))) 
{ 
}

I can manage to avoid cache issue by setting the time() in the filename, but by this way opencart will constantly create new images unnecessarily.

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

Deleting image/cache/myfolder/* does no effect whatsoever.

  • 写回答

1条回答 默认 最新

  • dqjmq28248 2017-01-23 15:14
    关注

    Solved.

    Change my function to the following:

    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;
    }
    

    This way, it only generates one time the image.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站