mypics.php?mypics=band&PageNo=2 $img=opendir("./".$mypics); //Open the directory //Create the function to read the caption text file function My_Read_Caption_File($mypics) { $i=0; if(file_exists($mypics."/".$mypics.".txt")) //check to see if it exists { $mytextarray=file($mypics.'/'.$mypics.'.txt'); $number_of_text=count($mytextarray); //Count the line items in the text file if($number_of_text != 0) //check to make sure text file isn't empty { for ($i=0; $i<$number_of_text; $i++) { //I would document this if I could figure out what I did $pictext=explode("\n", implode("",$mytextarray)); list($filename,$text)=explode("\t",$pictext[$i]); $textarray[$filename] = $text; } return $textarray; //returns the $textarray - the data read from the text file as an array } } return; } $textarray=my_read_caption_file($mypics); //calls the function to get the text from the text file if(isset($mypicture)) //This branch taken if a picture has been selected, then display it { echo '
'; //class is in BobStyles.css echo ''; echo $textarray[$mypicture]; echo '
'; } else //if a picture is not set then it means we want to display the thumbs { $i=0; //added thisline to see if it makes it work. while ($file=readdir($img)) //read the filenames from sub defined in $img (open statement) { // echo readdir($img); // echo ""; if(stristr($file,".jpg")||stristr($file,".png")||stristr($file,".JPG")||stristr($file,".PNG")) //check to see if jpg, png (should add jpeg) { if(file_exists("./".$mypics."/thumbs/t".$file)) //check to see if thumbs subdir exists { $myfiles[$i]=$file; //builds array for later use $i++; } } } if(is_array($myfiles)) { sort($myfiles); //sorts the array by name } else { echo "Array not found in ".$mypics."\n"; //This line isn't working right any more - $myfiles is not built as an array? } $ImgPerPage=15; $ImgCount=count($myfiles); //Number of files $Pages = intval($ImgCount / $ImgPerPage); //Integer part of result if(fmod($ImgCount,$ImgPerPage)) //If a remainder then add one to page count { $Pages++; } // if(!isset($PageNo)) // For some reason this negative test no longer works // Reversed the test to a positive to see if I could get it to work and it did 1/25/10. if(isset($PageNo)) // If this is the first time through and no page has been selected, then select page 1 { // do nothing - ie $PageNo is set so we'll use it } else // if no page number then set it to page 1 { $PageNo = 1; } For ($i=1; $i<=$Pages; $i++) //Create selectable page number text { $MyPageText= $MyPageText.'['.$i.']  '; } echo '

'; Echo "Pages: ".$MyPageText.'

'; //Display the page number text //Start of FOR loop to display the images on the selected page for ($i=($PageNo-1)*$ImgPerPage; $i<($PageNo)*$ImgPerPage; $i++) { if($i<$ImgCount) //Check to see if $i exceeded the number of images { $filename=$myfiles[$i]; //Get the filename from the myfiles array for $i echo '
'. ''; //If there's text in the text file for this filename, then display it if(isset($textarray[$filename])) { if(strlen($textarray[$filename])<40) //check to see if text is too long { echo $textarray[$filename]; } else //If too long display on the first 36 characters with the thumb { echo substr($textarray[$filename],0,36).'...'; } } echo '
'; } Else { // Not sure what to put here to jump out of the for loop before the end. } } // End of display thumbs FOR loop echo '

'; echo "Page: ".$PageNo."

"; echo '

'; Echo "Pages: ".$MyPageText; } // End of Else branch for getting subdir filenames, text info and displaying thumbs echo '

'; //clean up and display footer require("footer.inc"); echo '

' ?>