# Zencart获取产品多图代码的解析

**URL:** <https://www.isharkfly.com/t/zencart/5493>\
**Category:** PHP\
**Created:** [August 5, 2012, 3:01am UTC](https://www.isharkfly.com/t/zencart/5493 "2012-08-05T03:01:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [August 5, 2012, 3:01am UTC](https://www.isharkfly.com/t/zencart/5493/1 "2012-08-05T03:01:12Z")

</div>

zencart默认的获取产品多图的代码在includes\modules\additional\_images.php文件里面，主要的代码在

// Check for additional matching images  
$file\_extension = $products\_image\_extension;  
$products\_image\_match\_array = array();  
if ($dir = @dir($products\_image\_directory)) {  
while ($file = $dir-\>read()) {  
if (!is\_dir($products\_image\_directory . $file)) {  
if (substr($file, strrpos($file, ‘.’)) == $file\_extension) {  
// if(preg\_match(“/” . $products\_image\_match . “/i”, $file) == ‘1’) {  
if(preg\_match(“/” . $products\_image\_base . “/i”, $file) == 1) {  
if ($file != $products\_image) {  
if ($products\_image\_base . str\_replace($products\_image\_base, ‘’, $file) == $file) {  
// echo 'I AM A MATCH ’ . $file . ‘  
’;  
$images\_array = $file;  
} else {  
// echo 'I AM NOT A MATCH ’ . $file . ‘  
’;  
}  
}  
}  
}  
}  
}  
if (sizeof($images\_array)) {  
sort($images\_array);  
}  
$dir-\>close();  
}  
主要根据主图所在的位置目录下面，按主题的文件名来匹配，然后把所有的图片保存在$products\_image\_match\_array数组里面。匹配规则：  
“/” . $products\_image\_base . “/i”  
zencart后台默认没有提供上传多图的功能，但是images handler插件提供了多图管理的功能。
