我必须使用以下条件从文件夹中压缩图像: - >仅包含最新发布日期和库存>的30张图片30。
我是这样做的: - 首先,我需要从xml文件中获取图像的名称。 - 我检查具有名称的图像是否存在。 - 如果文件夹中存在具有该名称的图像,我将该图像放入zip文件
代码在这里:
<?php
$document = new DOMDocument('1.0', 'UTF-8');
$document->preserveWhiteSpace = true;
$document->formatOutput = true;
$document->load('after_filter_xml.xml');
getlatestproductimage ($document);
function getlatestproductimage($doc) {
$xpath = new DOMXPath($doc);
$zipname = 'latestimage.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($xpath->evaluate('//item') as $item) {
$url = $xpath->evaluate('string(g:promotion_image_url)', $item);
$name = basename($url);
$stock = $xpath->evaluate('string(g:avail)', $item);
$category= $xpath->evaluate('string(g:main_category_name)', $item);
if ($zip->numFiles < 30) {
if($category== 'Jeans' && $stock >= 30) {
if (file_exists('images/promo_images'.$name)) {
$put_file = file_get_contents($name);
$zip->addFromString($name, $put_file);
}
}
}
}
$zip->close();
}
?>
我正在尝试这样做,但它没有给我任何结果。我的代码有什么问题吗?谢谢你的帮助