Moin hgtwn,
you go recursivly into the subdirs but never catch the result of the function:
- Code: Select all
if (is_dir($curpath.$file)) {
ls($curpath.$file."/",$p);
}
This should be:
- Code: Select all
if (is_dir($curpath.$file)) {
files[] = ls($curpath.$file."/",$p);
}
You don't really need $p in this example, use $files[] instead and
- Code: Select all
while ($file = $dir->read())
should be
- Code: Select all
while (false !== ($file = $dir->read()))
In the first case a directory/file named 'false' or '0' will evaluate to a logical false and break the while...
So the result is:
- Code: Select all
function ls($curpath) {
$files = array();
$dir = dir($curpath);
while (false !== ($file = $dir->read())) {
if($file != "." && $file != "..") {
if (is_dir($curpath.$file)) {
$files[] = ls($curpath.$file."/");
} else if (eregi("\.jpg",$file)) {
$files[] = $file;
}
}
}
$dir->close();
return $files;
}
$files = ls('random images/');
print_r($files);
mfg straffi