RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
Posted: Sat Mar 10, 2007 5:06 pm Post subject: Modify PHP Slideshow script to include sub folders |
|
|
Here is the part of a slide show script i use to retrieve and display images:
Code: |
<?php
function returnimages($dirname, $start) {
$pattern="(\.jpg$)|(\.jpeg$)"; //valid image extensions
$curimage=$start;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'galleryarray['.$curimage.']="'.$dirname.''.$file .'";';
$curimage++;
}
}
closedir($handle);
}
return($curimage);
}
$start = 0;
echo 'var galleryarray=new Array();'; //Define array in JavaScript
$start = returnimages("gallery/All Teams/", $start);
$start = returnimages("gallery/varsity/", $start);
$start = returnimages("gallery/junior varsity/", $start);
$start = returnimages("gallery/freshman/", $start);
$start = returnimages("gallery/Scrimmage-Cookout/", $start);
?>
|
You can see at the end there a list of folders to pull images from. Problem is, some of those folders have sub folders in them. IS there an easy way to modify the code to automatically pull images from the sub folders too? |
|