communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "directories" - download "recursive directory listing"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

directories - recursive directory listing was created/last modified on Sat 08 May 2004 3:35 PM

a function to scan directories recursively and save the result to an array with informations like level, path, name and file informations.
   
<?php
   
   
   
function recur_dir($dir)
   {
       
$dirlist = opendir($dir);
       while (
$file = readdir ($dirlist))
       {
           if (
$file != '.' && $file != '..')
           {
               
$newpath = $dir.'/'.$file;
               
$level = explode('/',$newpath);
               if (
is_dir($newpath))
               {
                   
$mod_array[] = array(
                           
'level'=>count($level)-1,
                           
'path'=>$newpath,
                           
'name'=>end($level),
                           
'kind'=>'dir',
                           
'mod_time'=>filemtime($newpath),
                           
'content'=>recur_dir($newpath));
               }else{
  
                   
$mod_array[] = array(
                           
'level'=>count($level)-1,
                           
'path'=>$newpath,
                           
'name'=>end($level),
                           
'kind'=>'file',
                           
'mod_time'=>filemtime($newpath),
                           
'size'=>filesize($newpath));
              }
           }
       }
       
closedir($dirlist);
       return
$mod_array;
   }
   
   echo
'<pre>';
   
print_r(recur_dir('.'));
   echo
'</pre>';
   
?>

learn more about some of the PHP functions used in this snippet: array, closedir, count, dir, echo, else, end, explode, file, filemtime, filesize, for, function, is_dir, list, opendir, print, print_r, readdir, return, save, time, while

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari