# 附加图片文件additional\_images.php

**URL:** <https://www.isharkfly.com/t/additional-images-php/3818>\
**Category:** PHP\
**Created:** [August 5, 2012, 3:03am UTC](https://www.isharkfly.com/t/additional-images-php/3818 "2012-08-05T03:03:56Z")\
**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:03am UTC](https://www.isharkfly.com/t/additional-images-php/3818/1 "2012-08-05T03:03:56Z")

</div>

additional\_images.php 文件是产品页面大图片下面的附加额外的图片，如果有多张图片的话才会显示出来。处理多张图片的话，建议安装Images handler插件，这个是很优秀的一个图片管理插件，应该说是zencart网店必备的一个插件。这个文件的实现机制就是通过数据库保存的产品图片的URI，然后找到该产品的主图片所在图片目录下面，通过匹配出跟这个主图片一样的其他图片，然后保存所有的图片到一个数组（$images\_array），如果有其他图片的话才会显示出来。一些图片浏览插件主要的还是修改这个文件或者重新这个文件的程序来达到想要的效果。以下程序就是获取其他匹配的图片，有兴趣的话可以自己看看，研究一下。这里就是简单的介绍这个文件的意义所在

// 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();  
}
