note 12091 rejected from function.readdir by sander

From: Date: Sat, 06 Apr 2002 19:15:08 +0000
Subject: note 12091 rejected from function.readdir by sander
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28751@lists.php.net to get a copy of this message
One more example : - This code goes through directories. - Set links on files. - Display the result in HTML with files first then directories. <?php function GET_TREE_INFO($root_file_path,$apache_root,$display_directories,$level) { // ***************************************** // Get file and directorie names routine // ***************************************** $handle=opendir($root_file_path); while (($file = readdir($handle))!=false) { if (strcmp(".",$file)!=0 && strcmp("..",$file)!=0) { if (is_dir("$root_file_path/$file")==true) { // Get directorie names into an array $directories_list[count($directories_list)] = $file; } else { // Get file names into an array $files_list[count($files_list)] = $file; } } } clearstatcache(); closedir($handle); // ***************** // Display routine // ***************** if (count($files_list)>0) { // Sort file table sort($files_list); while (list($key,$val) = each($files_list)) { // Check directories comutator // ******************************* if ($display_directories==true) { // This is a file // ************* $link_file_path=substr ($root_file_path,strlen($apache_root)); // Display file name and link echo "<A HREF=\"$link_file_path/$val\">$val</A><BR>\n"; } } } if (count($directories_list)>0) { // Sort directories table sort($directories_list); while (list($key, $val) = each($directories_list)) { // This is a directory // ******************** // Insert a rule if level = 1 if ($level==1) echo "<div align=\"center\"><img src=\"/images/barre.jpg\" width=\"250\" height=\"16\" align=\"middle\"></div>\n"; // Check if level = 7 (stay at level 6) because H7 doesn't exist if ($level==7) $level=6; // Display directory name echo "<H".$level.">".$val."</H".$level.">\n"; // Recursive part GET_TREE_INFO("$root_file_path/$val","$apache_root",$display_directories,$level+1); } } } GET_TREE_INFO("/home/www","/home/www",true,1); ?>

« previous php.notes (#28751) next »