PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Mon Dec 08, 2003 1:51 pm
Hello,
the following is a script that searches an 'images' directory for folders within it
Code: Select all
$dir = dir($path);
while (false !== ($content = $dir->read())){
// get files
if($TYPE == 'files'){
if($content != "." && $content != ".." && (($ext = strstr($content,$NOT)) != false)){
if(!is_dir($content)){
// get file stats
$date = filemtime($path.'/'.$content);
$CONTENTS[$date] = $content;
}
}
}
if($TYPE == 'folder'){
if(is_dir($content)){
echo 'debug folder function GET DIR - content - '.$content.'<br>';
$date = filemtime($path.'/'.$content);
$CONTENTS[$date] = $content;
}
}
}
$dir->close();
return $CONTENTS;
My problem is it does not return the directories within the 'images' folder...and they are folders there.
however if i !is_dir() i do get it along with the image files as well.
What is wrong here.
Kendall
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Mon Dec 08, 2003 4:45 pm
you need to construct the relative path to the file as $dir->read() returns filename only. Do it like you're doing it for filemtime function:
Code: Select all
if(is_dir($path."/".$content))
//do something
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Tue Dec 09, 2003 8:30 am
Wierd,
hmmm...is this really what i ought to do?....the thing is if i were to change the path to search for folders within the same "root" it would turn up fine. but i will try your scenario.
Thanks
Kendall