Modify PHP Slideshow script to include sub folders

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Sat Mar 10, 2007 5:06 pm    Post subject: Modify PHP Slideshow script to include sub folders Reply with quote

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?
Back to top View user's profile Send private message
loloyd
-


Joined: 03 Mar 2006
Posts: 435
Location: Philippines

PostPosted: Sun Mar 11, 2007 4:49 pm    Post subject: Reply with quote

I'm not PHP savvy but I can imagine a way on how you can do this as I have done it on other programming languages. You have to recursively do opendir() and readdir() for each directory until you can't find a unique full subdirectory pathname anymore in each of their trees. You can save the full subdirectory name you have read in an array for quick checking if you have processed that subdirectory already. Good luck.
_________________

http://home.loloyd.com/ is online if the logo graphic at left is showing.
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group