如何从 Prestashop 导入中跳过损坏的图像 URL?
How to skip broken Images URL from Prestashop Import?
我正在将产品目录导入 Prestashop 商店,但图像 url 损坏时出现问题,因为显示的产品带有带有询问符号的默认图像。
我的想法是跳过那些url并且不使用默认的未知图像。有什么想法吗??
这是图像 url 损坏时使用的默认图像
由于图片丢失,本产品默认带有部分图片
产品图片列在 ps_image
table 中。您应该执行一个脚本来删除所有 table 不存在于 /img/p/
文件夹中的图像。
您可以在 backffoffice 图像选项菜单中调整图像大小,但我不确定这个数据库是否干净。
祝你好运。
感谢您的帮助。我可以执行该脚本,但该解决方案不会有用,因为我每小时导入一次目录。
我想出了一个解决方案,它正在向导入模块添加一些更改,所以现在导入 url 之前的模块会检查 file_exists()
而不是抛出新的异常 do unset()
用于该图像 url 所以对于我的解决方案来说已经足够了。谢谢大家
这是代码:
// Get images real path, and check exists
foreach ($images as $key => $img) {
/*if (preg_match('/:\/\//', $images[$key]->value)) {
continue;
}*/
$url = $images[$key]->value;
$filename = explode('=',$url)[1];
$images[$key]->value = _PS_ROOT_DIR_.'/testimg/'.$filename.'.jpg';
if (!file_exists($images[$key]->value))
{
unset($images[$key]);
//throw new Exception("File {$images[$key]->value} not found.");
}
}
我正在将产品目录导入 Prestashop 商店,但图像 url 损坏时出现问题,因为显示的产品带有带有询问符号的默认图像。
我的想法是跳过那些url并且不使用默认的未知图像。有什么想法吗??
这是图像 url 损坏时使用的默认图像
由于图片丢失,本产品默认带有部分图片
产品图片列在 ps_image
table 中。您应该执行一个脚本来删除所有 table 不存在于 /img/p/
文件夹中的图像。
您可以在 backffoffice 图像选项菜单中调整图像大小,但我不确定这个数据库是否干净。
祝你好运。
感谢您的帮助。我可以执行该脚本,但该解决方案不会有用,因为我每小时导入一次目录。
我想出了一个解决方案,它正在向导入模块添加一些更改,所以现在导入 url 之前的模块会检查 file_exists()
而不是抛出新的异常 do unset()
用于该图像 url 所以对于我的解决方案来说已经足够了。谢谢大家
这是代码:
// Get images real path, and check exists
foreach ($images as $key => $img) {
/*if (preg_match('/:\/\//', $images[$key]->value)) {
continue;
}*/
$url = $images[$key]->value;
$filename = explode('=',$url)[1];
$images[$key]->value = _PS_ROOT_DIR_.'/testimg/'.$filename.'.jpg';
if (!file_exists($images[$key]->value))
{
unset($images[$key]);
//throw new Exception("File {$images[$key]->value} not found.");
}
}