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 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!