You are here: only list dirs if they have jpgs inside « PHP Programming Language « IT news, forums, messages
only list dirs if they have jpgs inside

Posted by J. Frank Parnell on 08/01/07 04:52

Hi there,
I got this directory tree listing function somewhere, it works great,
but I want it to only list directories that do have one or more .jpgs
inside. I tried getting a list of each dir's contents and doing
if count($dir) > 0
But something not working out for me.

<?php

// $path : path to browse
// $maxdepth : how deep to browse (-1=unlimited)
// $mode : "FULL"|"DIRS"|"FILES"
// $d : must not be defined
function searchdir( $path , $maxdepth = -1 , $mode = "FULL" , $d = 0 )
{
if ( substr ( $path , strlen ( $path ) - 1 ) != '/' )
{ $path .= '/' ; }

$dirlist = array () ;
if ( $mode != "FILES" )
{ $dirlist[] = $path ; }

if ( $handle = opendir ( $path ) ){
while ( false !== ( $file = readdir ( $handle ) ) ){
if ( $file != '.' && $file != '..' ){
$file = $path . $file ;

if ( ! is_dir ( $file ) ) {
if ( $mode != "DIRS" ){$dirlist[] = $file ;} //if ( $mode NOT "DIRS" )
}elseif ( ($d >=0) AND ($d < $maxdepth || $maxdepth < 0) ) {
$result = searchdir ( $file . '/' , $maxdepth , $mode , $d + 1 ) ;
$dirlist = array_merge ( $dirlist , $result ) ;
}//elsif
}//if ( $file != '.' && $file != '..' )
}// while reading
closedir ( $handle ) ;
}// if( $handle = opendir ( $path )
if ( $d == 0 ) { natcasesort ( $dirlist ) ; }
return ( $dirlist ) ;
}//func
?>

thanks

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация