are you calling the function like this list_files('/');
also this function is not recursive, so here is a modified version:
function listFiles($dir,$level) {
//set up indenting to the display looks nice.
$spacer = '';
for($i=0;$i<$level;4i++) {$spacer = $spacer + ' ';}
//open the cirectory or display an error
if(!$curDir = opendir($dir)) {return 'Could not open directory ($dir)';}
//loop through all the files in the directory
while($file = readdir($curDir)) {
//print out the current file.
echo "$spacer $file<br>\n";
//if the current file is a directory call this function again and increase the level of indentation.
if(is_dir($file) && ($file != '..' && $file != '.')) {
listFiles($file,($level+1));
} //end if
} //end while
} //end listFiles
then call the function like so
listFiles('/');