Opencart 删除 image/cache 什么都不做
Opencart deleting image/cache does nothing
我在使用 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/*
没有任何效果。
已解决。
将我的函数更改为以下内容:
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;
}
这样只生成一次图像
我在使用 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/*
没有任何效果。
已解决。
将我的函数更改为以下内容:
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;
}
这样只生成一次图像