1
我有一个巨大的目录充满了图像。这些图像在1到3个目录之间很深。我使用PHP5目录迭代来返回这些文件中的每一个的路径,即将建立一个XML文件以后。分组和处理循环结果的部分结果在php
什么即时尝试做,是一旦我到达与一组图像的目录,编号喜欢将这些图像存储在一个数组,然后我可以循环和处理。
我使用下面的代码,它让我读出所有图像,完整的目录;
$it = new RecursiveDirectoryIterator("basedir/");
foreach(new RecursiveIteratorIterator($it) as $file) {
$filearray = explode("/", $file);
unset($output);
foreach ($filearray AS $key=>$value){
if(strstr($value, 'basedir')){
$output .= ""; //ignore the top level directory
}else if(!strstr($value, '.jpg') && !strstr($value, '.JPG')){
$output .= "$value - "; //if its a directory name and not an image, add the path
}else{
$output .= "$value <br>"; //if its a picture, add the filename and linebreak
}
}
echo $output;
这会导致类似于下面的输出;
accessories - J.L. Johnson Bridals 2011 - 123.jpg
accessories - J.L. Johnson Bridals 2011 - 234.jpg
accessories - J.L. Johnson Bridals 2011 - 345.jpg
accessories - J.L. Johnson Bridals 2011 - 456.jpg
bridal - Allure Bridals - Women - 123.jpg
bridal - Allure Bridals - Women - 234.jpg
bridal - Allure Bridals - Women - 345.jpg
prom - MacDuggal Spring 2011 - MD prom - 123.jpg
prom - MacDuggal Spring 2011 - MD prom - 234.jpg
prom - MacDuggal Spring 2011 - MD prom - 345.jpg
prom - MacDuggal Spring 2011 - MD prom - 456.jpg
什么即时寻找来实现,被分组的图像在单个目录,或许到一个数组,即我可以来控制循环。像这样的东西;
accessories
J.L. Johnson Bridals 2011
123.jpg
234.jpg
345.jpg
456.jpg
bridal
Allure Bridals
Women
123.jpg
234.jpg
345.jpg
prom
MacDuggal Spring 2011
MD prom
123.jpg
234.jpg
345.jpg
456.jpg
伟大的作品,感谢您的帮助!它的排序就像我需要它,所以可以通过它。 – mrpatg 2011-01-28 11:59:29