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.

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

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳