I'm writing a script that loops through a series of directories and adds each filename (all jpgs) into an array (1 per dir), this works fine. I'm having trouble with the second part which loops through the 3 sets of 3 folders and generates an xml file for me to load into Flash (MX, not that that matters). I works fine if I just loop through 1 set of 3 (ie 1 for-loop) but if I add a second for loop (for determining which main directory I'm in) the code breaks ?? I've pasted the lot below and would really appreciate people ideas, hints etc into where I'm going wrong.
My dir structure is (repeated 3 times):
main folder: gallery
sub gallery folder: press
inside press folder: big, preview and thumbs
When I run an echo in the second for loop, instead of being returned the filename(s) of that index in the array, I get d,d,d, p,p,p j, j, j, - very weird. There are 2 images in each folder so why isn't it working ?
Here's my code:
Code: Select all
<?php
$galleries = array("djing","press","justforfun");
$djingBig = array();
$djingPreview = array();
$djingThumbs = array();
$pressBig = array();
$pressPreview = array();
$pressThumbs = array();
$justforfunBig = array();
$justforfunPreview = array();
$justforfunThumbs = array();
// gets all files in 'big' folder
if ($bigDir = opendir('./djing/big')) {
while (false !== ($file = readdir($bigDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($djingBig, $file);
}
}
closedir($bigDir);
}
// gets all files in 'preview' folder
if ($prevDir = opendir('./djing/preview')) {
while (false !== ($file = readdir($prevDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($djingPreview, $file);
}
}
closedir($prevDir);
}
// gets all files in 'thumbs' folder
if ($thumbsDir = opendir('./djing/thumbs')) {
while (false !== ($file = readdir($thumbsDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($djingThumbs, $file);
}
}
closedir($thumbsDir);
}
// gets all files in 'big' folder
if ($bigDir = opendir('./press/big')) {
while (false !== ($file = readdir($bigDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($pressBig, $file);
}
}
closedir($bigDir);
}
// gets all files in 'preview' folder
if ($prevDir = opendir('./press/preview')) {
while (false !== ($file = readdir($prevDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($pressPreview, $file);
}
}
closedir($prevDir);
}
// gets all files in 'thumbs' folder
if ($thumbsDir = opendir('./press/thumbs')) {
while (false !== ($file = readdir($thumbsDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($pressThumbs, $file);
}
}
closedir($thumbsDir);
}
// gets all files in 'big' folder
if ($bigDir = opendir('./justforfun/big')) {
while (false !== ($file = readdir($bigDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($justforfunBig, $file);
}
}
closedir($bigDir);
}
// gets all files in 'preview' folder
if ($prevDir = opendir('./justforfun/preview')) {
while (false !== ($file = readdir($prevDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($justforfunPreview, $file);
}
}
closedir($prevDir);
}
// gets all files in 'thumbs' folder
if ($thumbsDir = opendir('./justforfun/thumbs')) {
while (false !== ($file = readdir($thumbsDir))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
array_push ($justforfunThumbs, $file);
}
}
closedir($thumbsDir);
}
//echo $bigXML;
$totalGalleries = count($galleries);
//print $galleriesї0];
$theXML = "<" ;
$theXML .= "?";
$theXML .= "xml version='1.0'";
$theXML .= "?";
$theXML .= ">\n";
$theXML .= "\t<gallery>\n";
for($i=0; $i<$totalGalleries; $i++)
{
$theXML .= "\t<" . $galleriesї$i] . ">\n";
$currentBig = $galleriesї$i] . "Big";
$currentPreview = $galleriesї$i] . "Preview";
$currentThumbs = $galleriesї$i] . "Thumbs";
//echo (!is_array($currentBig));
//echo("<br>");
$totalImages = count($currentBig);
//echo($currentBig . "<br>");
//echo($totalImages . "<br>");
for($j=0; $j<$totalImages ; $j++)
{
echo($currentBigї$j] . "<br>");
echo($currentPreviewї$j] . "<br>");
echo($currentThumbsї$j] . "<br><br>");
$theXML .= "\t\t\t<item>\n";
$theXML .= "\t\t\t\t<bigImageURL>big/" . $currentBigї$j] . "</bigImageURL>\n";
$theXML .= "\t\t\t\t<previewImageURL>preview/" . $currentPreviewї$j] . "</previewImageURL>\n";
$theXML .= "\t\t\t\t<thumbImageURL>thumbs/" . $currentThumbsї$j] . "</thumbImageURL>\n";
$theXML .= "\t\t\t</item>\n";
}
$theXML .= "\t</" . $galleriesї$i] . ">\n";
}
$theXML .= "\t</gallery>";
//echo($theXML);
?>Jon