linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file class.afiles.php

Documentation is available at class.afiles.php

  1. <?php
  2. /**
  3.  * @package linea21.externals
  4.  * @subpackage Absynthe-files
  5.  * @author Sylvain 'Absynthe' Rabot <sylvain@abstraction.fr> , modified by Linea21 <info@linea21.com>
  6.  * @link http://absynthe.is.free.fr/aFiles/
  7.  * @version alpha 2.2
  8.  * @access public
  9.  * @license http://opensource.org/licenses/gpl-3.0.html
  10.  *  Absynthe files
  11.  */
  12.  
  13.  
  14. class afiles
  15. {
  16.     /**
  17.      * Default path to an entity
  18.      * @var string 
  19.      * @access private
  20.      */
  21.     var $path    false;
  22.     
  23.     /**
  24.      * Constructor which allows to chose the path of the entity used for following actions
  25.      * @param string $path 
  26.      */
  27.      function __construct($path false)
  28.     {
  29.         $this->path $path;
  30.     }
  31.     
  32.     /**
  33.      * Methods which allows to chose the path of the entity used for following actions
  34.      * @param string $path 
  35.      */
  36.      function set_path($path false)
  37.     {
  38.         $this->path $path;
  39.     }
  40.     
  41.     /**
  42.      * Return the path of the entity used by default
  43.      * @return string 
  44.      */
  45.      function get_path()
  46.     {
  47.         return $this->path;
  48.     }
  49.     
  50.     /**
  51.      * Return the type of an entity
  52.      * @param string $path 
  53.      * @return string 
  54.      */
  55.      function type($path null)
  56.     {
  57.         $this->test_var($path$this->path);
  58.         
  59.         if (is_dir($path))
  60.             return 'dir';
  61.             
  62.         else if (is_file($path))
  63.             return 'file';
  64.         
  65.         else
  66.             return false;
  67.     }
  68.     
  69.     /**
  70.      * Return the list of all entity included in the path
  71.      * @param string $path 
  72.      * @param boolean $withroot 
  73.      * @return array 
  74.      */
  75.      function ls($path null$withroot true)
  76.     {
  77.         $this->test_var($path$this->path);
  78.         
  79.         if (!is_dir($path))
  80.             return false;
  81.             
  82.         if ($handle opendir($path))
  83.         {
  84.             while (false !== ($file readdir($handle))) 
  85.             {
  86.                 if ($file != '..' && $file != '.' && $file != '')
  87.                 {
  88.                     if ($withroot)
  89.                         $infos[$path.'/'.$file;
  90.                         
  91.                     else
  92.                         $infos[$file;
  93.                 }
  94.             }
  95.             
  96.             closedir($handle);
  97.             
  98.             $infos array_map(array($this'format_path')$infos);
  99.             
  100.             return $infos;
  101.         }
  102.         else
  103.         {
  104.             return false;
  105.         }
  106.     }
  107.     
  108.     /**
  109.      * Return the list of directories included in the path
  110.      * @param string $path 
  111.      * @param boolean $withroot 
  112.      * @return array 
  113.      */
  114.      function lsd($path null$withroot true)
  115.     {
  116.         $this->test_var($path$this->path);
  117.         
  118.         if (!is_dir($path))
  119.             return false;
  120.         
  121.         $infos array();
  122.         
  123.         if ($handle opendir($path))
  124.         {
  125.             while (false !== ($file readdir($handle)))
  126.             {
  127.                 if (is_dir($path.'/'.$file)) 
  128.                 {
  129.                     if ($file != '..' && $file != '.' && $file != '')
  130.                     {
  131.                         if ($withroot)
  132.                             $infos[$path.'/'.$file;
  133.                             
  134.                         else
  135.                             $infos[$file;
  136.                     }
  137.                 }
  138.             }
  139.             
  140.             $infos array_map(array($this'format_path')$infos);
  141.             closedir($handle);
  142.             
  143.             return $infos;
  144.         }
  145.         else
  146.         {
  147.             return false;
  148.         }
  149.     }
  150.     
  151.     /**
  152.      * Return infos of all entity included in the path
  153.      * @param string $path 
  154.      * @param boolean $withroot 
  155.      * @return array 
  156.      */
  157.      function ll($path null$withroot true)
  158.     {
  159.         $this->test_var($path$this->path);
  160.         
  161.         if (!is_dir($path))
  162.             return false;
  163.             
  164.         if ($handle opendir($path))
  165.         {
  166.             while (false !== ($file readdir($handle))) 
  167.             {
  168.                 if ($file != '..' && $file != '.' && $file != '')
  169.                 {
  170.                     if ($withroot)
  171.                     {
  172.                         $temp $this->format_path($path.'/'.$file);
  173.                         $infos[$temp$this->infos($temp);
  174.                     }
  175.                     else
  176.                     {
  177.                         $temp $this->format_path($file);
  178.                         $infos[$temp$this->infos($path.'/'.$file);
  179.                     }
  180.                 }
  181.             }
  182.             
  183.             closedir($handle);
  184.             
  185.             return $infos;
  186.         }
  187.         else
  188.         {
  189.             return false;
  190.         }
  191.     }
  192.     
  193.     /**
  194.      * Return infos of all directories included in the path
  195.      * @param string $path 
  196.      * @param boolean $withroot 
  197.      * @return array 
  198.      */
  199.      function lld($path null$withroot true)
  200.     {
  201.         $this->test_var($path$this->path);
  202.         
  203.         if (!is_dir($path))
  204.             return false;
  205.             
  206.         if ($handle opendir($path))
  207.         {
  208.             while (false !== ($file readdir($handle))) 
  209.             {
  210.                 if (is_dir($path.'/'.$file))
  211.                 {
  212.                     if ($file != '..' && $file != '.' && $file != '')
  213.                     {
  214.                         if ($withroot)
  215.                         {
  216.                             $temp $this->format_path($path.'/'.$file);
  217.                             $infos[$temp$this->infos($temp);
  218.                         }
  219.                         else
  220.                         {
  221.                             $temp $this->format_path($file);
  222.                             $infos[$temp$this->infos($path.'/'.$file);
  223.                         }
  224.                     }
  225.                 }
  226.             }
  227.             
  228.             closedir($handle);
  229.             
  230.             return $infos;
  231.         }
  232.         else
  233.         {
  234.             return false;
  235.         }
  236.     }
  237.     
  238.     /**
  239.      * Create a file with or without content
  240.      * @param string $content 
  241.      * @param string $path 
  242.      * @return boolean 
  243.      */
  244.      function mkfile($content ''$path null)
  245.     {
  246.         $this->test_var($path$this->path);
  247.         
  248.         if ($handle fopen($path'w+'))
  249.         {
  250.             if (strlen($content!= 0)
  251.                 fwrite($handle$content);
  252.                 
  253.             fclose($handle);
  254.             
  255.             return true;
  256.         }
  257.         else
  258.         {
  259.             return false;
  260.         }
  261.     }
  262.     
  263.     /**
  264.      * Read the content of a file
  265.      * @param string $path 
  266.      * @param boolean $byline 
  267.      * @param int $length 
  268.      * @return string/array 
  269.      */
  270.      function read_file($path null$byline false$length 1024)
  271.     {
  272.         $this->test_var($path$this->path);
  273.         
  274.         if (!is_file($path))
  275.             return false;
  276.         
  277.         if ($byline)
  278.         {
  279.             if ($handle fopen($path'r'))
  280.             {
  281.                 while (!feof($handle)) 
  282.                     $lines[fgets($handle$length);
  283.                 
  284.                 fclose($handle);
  285.                 
  286.                 return $lines;
  287.             }
  288.             else
  289.                 return false;
  290.         }
  291.         else
  292.         {
  293.             return file_get_contents($path);
  294.         }
  295.     }
  296.     
  297.     /**
  298.      * Create a directory with/without chmod
  299.      * @param string $path 
  300.      * @param int $chmod 
  301.      * @return boolean 
  302.      */
  303.      function mkdir($path null$chmod null)
  304.     {
  305.         $this->test_var($path$this->path);
  306.         
  307.         if (@mkdir($path))
  308.         {
  309.             if (!is_null($chmod))
  310.                 chmod($path$chmod);
  311.                 
  312.             return true;
  313.         }
  314.         else
  315.         {
  316.             return false;
  317.         }
  318.     }
  319.     
  320.     /**
  321.      * Move a file or a directory
  322.      * @param string $path 
  323.      * @param string $where 
  324.      * @return boolean 
  325.      */
  326.      function mv($path$where)
  327.     {    
  328.         if (!is_dir($where))
  329.             return false;
  330.         
  331.         if (is_dir($path))
  332.         {
  333.             $tree $this->tree($path);
  334.             $this->cp($path$where);
  335.             $this->rm($tree);
  336.         }
  337.         else if (is_file($path))
  338.         {
  339.             $this->cp($path$where);
  340.             $this->rm($path);
  341.         }
  342.         
  343.         return true;
  344.     }
  345.     
  346.     /**
  347.      * Remove files or/and directories
  348.      * @param string $path 
  349.      * @return boolean 
  350.      */
  351.      function rm($path null)
  352.     {
  353.         $this->test_var($path$this->path);
  354.         
  355.         if (!is_array($path))
  356.             $path array($path);
  357.         
  358.         foreach ($path as $file)
  359.         {
  360.             if (is_dir($file))
  361.             {
  362.                 $tree $this->tree($file);
  363.                 rsort($tree);
  364.                 
  365.                 foreach ($tree as $f)
  366.                 {
  367.                     if (is_dir($f))
  368.                         rmdir($f);
  369.  
  370.                     else if (is_file($f))
  371.                         unlink($f);
  372.                 }
  373.             }
  374.             else if (is_file($file))
  375.             {
  376.                 unlink($file);
  377.             }
  378.             else
  379.             {
  380.                 return false;
  381.             }
  382.         }
  383.         
  384.         return true;
  385.     }
  386.     
  387.     /**
  388.      * Copy files or/and directories
  389.      * @param string $path 
  390.      * @param string $where 
  391.      * @return boolean 
  392.      */
  393.      function cp($path$where)
  394.     {    
  395.         if (!is_dir($where))
  396.             return false;
  397.             
  398.         if (!is_array($path))
  399.             {
  400.                 if (is_file($path))
  401.                 {
  402.                 $file_name end(explode("/"$path));
  403.                 copy($path$where.'/'.$file_name);
  404.                 }
  405.             }
  406.         else
  407.         {    
  408.         foreach($path as $file)
  409.         {
  410.             if (is_file($file))
  411.                 {
  412.                 $file_name end(explode("/"$file));
  413.                 copy($file$where.'/'.$file_name);
  414.                 }
  415.                 
  416.             else if (is_dir($file))
  417.             {
  418.                 $files $this->tree($file);
  419.                 $this->mkdir($where.'/'.$file);
  420.                 
  421.                 foreach ($files as $f)
  422.                 {
  423.                     if (is_file($f))
  424.                         copy($f$where.'/'.$f);
  425.                     else if (is_dir($f))
  426.                         $this->mkdir($where.'/'.$f);
  427.                 }
  428.             }
  429.         }
  430.         }
  431.         
  432.         return true;
  433.     }
  434.     
  435.     /**
  436.      * Return the mod of a file/directory
  437.      * Credits goes to Ambriel_Angel (www dot ambriels dot net)
  438.      * @param string $path 
  439.      * @return int 
  440.      */
  441.      function mod($path
  442.     {
  443.         $this->test_var($path$this->path);
  444.         
  445.         // Initialisation
  446.         $val    0;
  447.         $perms    fileperms($path);
  448.         
  449.         // Owner; User
  450.         $val += (($perms 0x01000x0100 0x0000);        // Read
  451.         $val += (($perms 0x00800x0080 0x0000);        // Write
  452.         $val += (($perms 0x00400x0040 0x0000);        // Execute
  453.  
  454.         // Group
  455.         $val += (($perms 0x00200x0020 0x0000);        // Read
  456.         $val += (($perms 0x00100x0010 0x0000);        // Write
  457.         $val += (($perms 0x00080x0008 0x0000);        // Execute
  458.  
  459.         // Global; World
  460.         $val += (($perms 0x00040x0004 0x0000);        // Read
  461.         $val += (($perms 0x00020x0002 0x0000);        // Write
  462.         $val += (($perms 0x00010x0001 0x0000);        //    Execute
  463.  
  464.         // Misc
  465.         $val += (($perms 0x400000x40000 0x0000);    // temporary file (01000000)
  466.         $val += (($perms 0x800000x80000 0x0000);     // compressed file (02000000)
  467.         $val += (($perms 0x1000000x100000 0x0000);    // sparse file (04000000)
  468.         $val += (($perms 0x08000x0800 0x0000);        // Hidden file (setuid bit) (04000)
  469.         $val += (($perms 0x04000x0400 0x0000);        // System file (setgid bit) (02000)
  470.         $val += (($perms 0x02000x0200 0x0000);        // Archive bit (sticky bit) (01000)
  471.  
  472.         return decoct($val);
  473.     }
  474.     
  475.     /**
  476.      * Return infos concerning the entity
  477.      * @param string $path 
  478.      * @param boolean $withroot 
  479.      * @param boolean $content 
  480.      * @param boolean $byline 
  481.      * @param int $length 
  482.      * @return array 
  483.      */
  484.      function infos($path null$withroot true$content true$byline false$length 1024)
  485.     {
  486.         $this->test_var($path$this->path);
  487.         
  488.         if (is_dir($path))
  489.         {
  490.             if ($handle opendir($path))
  491.             {
  492.                 $infos['type']            'dir';
  493.                 $infos['path_infos']    pathinfo($path);
  494.                 $infos['atime']            fileatime($path);
  495.                 $infos['ctime']            filectime($path);
  496.                 $infos['mtime']            filemtime($path);
  497.                 $infos['chmod']            $this->mod($path);
  498.                 $infos['owner_id']        fileowner($path);
  499.                 $infos['owner_infos']    posix_getpwuid($infos['owner_id']);
  500.                 $infos['group_id']        filegroup($path);
  501.                 $infos['group_infos']    posix_getgrgid($infos['group_id']);
  502.                 $infos['dir_count']        0;
  503.                 $infos['files_count']    0;
  504.                 $infos['size']            $this->filesize($path);
  505.                 $infos['files']            array();
  506.                 $infos['directories']    array();
  507.                 
  508.                 while (false !== ($file readdir($handle)))
  509.                 {
  510.                     if (is_dir($path.'/'.$file)) 
  511.                     {
  512.                         if ($file != '..' && $file != '.' && $file != '')
  513.                         {
  514.                             $infos['dir_count']++;
  515.                             if ($withroot)
  516.                                 $infos['directories'][$path.'/'.$file;
  517.                             else
  518.                                 $infos['directories'][$file;
  519.                         }
  520.                     }
  521.                     else if (is_file($path.'/'.$file))
  522.                     {
  523.                         $infos['files_count']++;
  524.                         
  525.                         if ($withroot)
  526.                             $infos['files'][$path.'/'.$file;
  527.                         else
  528.                             $infos['files'][$file;
  529.                     }
  530.                 }
  531.                 
  532.                 $infos['files']            array_map(array($this'format_path')$infos['files']);
  533.                 $infos['directories']    array_map(array($this'format_path')$infos['directories']);
  534.                 
  535.                 $this->sort_results($infos['directories']);
  536.                 $this->sort_results($infos['files']);
  537.                 
  538.                 closedir($handle);
  539.                 
  540.                 return $infos;
  541.             }
  542.             else
  543.             {
  544.                 return false;
  545.             }
  546.         }
  547.         else if (is_file($path))
  548.         {
  549.             if ($handle fopen($path'r')) 
  550.             {
  551.                 $infos['type']            'file';
  552.                 $infos['path_infos']    pathinfo($path);
  553.                 $infos['atime']            fileatime($path);
  554.                 $infos['ctime']            filectime($path);
  555.                 $infos['mtime']            filemtime($path);
  556.                 $infos['chmod']            $this->mod($path);
  557.                 $infos['owner_id']        fileowner($path);
  558.                 $infos['owner_infos']    posix_getpwuid($infos['owner_id']);
  559.                 $infos['group_id']        filegroup($path);
  560.                 $infos['group_infos']    posix_getgrgid($infos['group_id']);
  561.                 $infos['lines_count']    0;
  562.                 $infos['size']            $this->filesize($path);
  563.                 $infos['md5']            md5_file($path);
  564.                 $infos['sha1']            sha1_file($path);
  565.                 
  566.                 if ($content)
  567.                     $infos['content']        $byline === true array(file_get_contents($path);
  568.                 
  569.                 while (!feof($handle)) 
  570.                 {
  571.                     if ($byline && $content)
  572.                         $infos['content'][fgets($handle$length);
  573.                     else
  574.                         fgets($handle$length);
  575.                     
  576.                     $infos['lines_count']++;
  577.                 }
  578.                 
  579.                 fclose($handle);
  580.                 
  581.                 return $infos;
  582.             }
  583.             else
  584.             {
  585.                 return false;
  586.             }
  587.         }
  588.         else
  589.         {
  590.             return false;
  591.         }
  592.     }
  593.     
  594.     /**
  595.      * Return tree of a directory
  596.      * @param string $path 
  597.      * @param boolean $expand2files 
  598.      * @return array 
  599.      */
  600.      function tree($path null$expand2files true)
  601.     {
  602.         $this->test_var($path$this->path);
  603.         
  604.         $directories $this->lsd($path);
  605.         
  606.         for ($x 0$x count($directories)$x++)
  607.         {
  608.             if (!is_dir($directories[$x]))
  609.                 continue;
  610.                 
  611.             if ($handle opendir($directories[$x]))
  612.             {
  613.                 while (false !== ($file readdir($handle)))
  614.                 {
  615.                     if (is_dir($directories[$x]."/".$file)) 
  616.                     {
  617.                         if ($file != '..' && $file != '.' && $file != '')
  618.                         {
  619.                             $directories[$directories[$x]."/".$file;
  620.                         }
  621.                     }
  622.                 }
  623.                 closedir($handle);
  624.             }
  625.             else
  626.             {
  627.                 $directories[false;
  628.             }
  629.         }
  630.         
  631.         $directories[]    $path;
  632.         $directories    array_map(array($this'format_path')$directories);
  633.             
  634.         if ($expand2files)
  635.         {         
  636.             foreach ($directories as $dir)
  637.             {    
  638.                 $expanded_directories[$dir;
  639.                 
  640.                 if ($handle opendir($dir))
  641.                 {
  642.                     while (false !== ($file readdir($handle)))
  643.                         if (is_file($dir.'/'.$file))
  644.                             $expanded_directories[$dir.'/'.$file;
  645.                 }
  646.                 else
  647.                 {
  648.                     $expanded_directories[false;
  649.                 }
  650.             }
  651.             
  652.             $expanded_directories array_map(array($this'format_path')$expanded_directories);
  653.             
  654.             $this->sort_results($expanded_directories);
  655.         }
  656.         else
  657.         {
  658.             $this->sort_results($directories);
  659.         }
  660.         
  661.         return $expand2files === true $expanded_directories $directories;
  662.     }
  663.     
  664.     /**
  665.      * Return the size of an entity
  666.      * @param string $path 
  667.      * @return int 
  668.      */
  669.      function filesize($path null)
  670.     {
  671.         $this->test_var($path$this->path);
  672.         
  673.         if (is_file($path))
  674.             return filesize($path);
  675.         else
  676.         {
  677.             $tree $this->tree($path);
  678.             $size 0;
  679.             
  680.             foreach ($tree as $file)
  681.                 if (is_file($file))
  682.                     $size += filesize($file);
  683.                     
  684.             return $size;
  685.         }
  686.     }
  687.     
  688.     /**
  689.      * Serialize and creates a file with the serial
  690.      * @param anything $var 
  691.      * @param string $path 
  692.      * @return boolean 
  693.      */
  694.      function serialize($var$path null)
  695.     {
  696.         $this->test_var($path$this->path);
  697.         
  698.         if($this->mkfile(serialize($var)$path))
  699.             return true;
  700.         else
  701.             return false;
  702.     }
  703.     
  704.     /**
  705.      * Unserialize a file
  706.      * @param string $path 
  707.      * @return array 
  708.      */
  709.      function unserialize($path null)
  710.     {
  711.         $this->test_var($path$this->path);
  712.         
  713.         if(is_file($path))
  714.             return unserialize($this->read_file($path));
  715.         else
  716.             return false;
  717.     }
  718.     
  719.     /**
  720.      * Parse a ini file
  721.      * @param string $path 
  722.      * @return array 
  723.      */
  724.      function parse_ini($path null$whithsection true)
  725.     {
  726.         $this->test_var($path$this->path);
  727.         
  728.         if(is_file($path))
  729.             return parse_ini_file($path$whithsection);
  730.         else
  731.             return false;
  732.     }
  733.     
  734.     /**
  735.      * Make ini file
  736.      * @param array $content 
  737.      * @param string $path 
  738.      * @return boolean 
  739.      */
  740.      function mkini($content$path null)
  741.     {
  742.         $this->test_var($path$this->path);
  743.         
  744.         $out '';
  745.         
  746.         if (!is_array($content))
  747.             return false;
  748.         
  749.         foreach ($content as $key => $ini)
  750.         {
  751.             if (is_array($ini))
  752.             {
  753.                 $out .= "\n[".$key."]\n\n";
  754.                 
  755.                 foreach ($ini as $var => $value)
  756.                 {
  757.                     $out .= $var." \t\t= ".$this->quote_ini($value)."\n";
  758.                 }
  759.             }
  760.             else
  761.             {
  762.                 $out .= $key." \t\t= ".$this->quote_ini($ini)."\n";
  763.             }
  764.         }
  765.         
  766.         return $this->mkfile($out$path);
  767.     }
  768.     
  769.     /* Private section                                     
  770.     ------------------------------------------------- */    
  771.  
  772.     /**
  773.      * Set a variable to $default parameter if it's null
  774.      * @param anything $var 
  775.      * @param anything $default 
  776.      */
  777.      function test_var(&$var$default)
  778.     {
  779.         if (is_null($var|| strlen(trim($var)) === 0)
  780.             $var $default;
  781.     }
  782.     
  783.     /**
  784.      * Replace '//' by '/' in paths
  785.      * @param string $path 
  786.      * @return string 
  787.      */
  788.      function format_path($path)
  789.     {
  790.         return preg_replace('#\/{2,}#''/'$path);
  791.     }
  792.     
  793.     /**
  794.      * Quote ini var if needed
  795.      * @param anything $var 
  796.      * @return anything 
  797.      */
  798.      /*function quote_ini($var)
  799.     {
  800.         return is_string($var) === true ? '"'.str_replace('"', '\"', $var).'"' : $var;
  801.     }
  802.     */
  803.     function quote_ini($var)
  804.     {        
  805.         if(is_numeric($var|| is_bool($var)) return $var;
  806.         else return '"'.str_replace('"''\"'$var).'"';
  807.  
  808.     }
  809.     /**
  810.      * Sort results
  811.      * @param array $array 
  812.      * @return array 
  813.      */
  814.      function sort_results(&$array)
  815.     {
  816.         if (is_array($array))
  817.             array_multisort(array_map('strtolower'$array)SORT_STRINGSORT_ASC$array);
  818.     }
  819.     
  820.       /**
  821.      * Apply the callback function on files with extension "filter"
  822.      * this method is recursive
  823.      * 
  824.      * @param  $directory 
  825.      * @return array 
  826.      */
  827. function lsr($directory$filter=false$directory_tree)
  828. {
  829.     // if the path has a slash at the end we remove it here
  830.     if(substr($directory,-1== '/')
  831.     {
  832.         $directory substr($directory,0,-1);
  833.     }
  834.  
  835.     // if the path is not valid or is not a directory ...
  836.     if(!file_exists($directory|| !is_dir($directory))
  837.     {
  838.         // ... we return false and exit the function
  839.         return false;
  840.  
  841.     // ... else if the path is readable
  842.     }elseif(is_readable($directory))
  843.     {
  844.         // we open the directory
  845.         $directory_list opendir($directory);
  846.  
  847.         // and scan through the items inside
  848.         while (false !== ($file readdir($directory_list)))
  849.         {
  850.             // if the filepointer is not the current directory
  851.             // or the parent directory
  852.             if($file != '.' && $file != '..')
  853.             {
  854.                 // we build the new path to scan
  855.                 $path $directory.'/'.$file;
  856.  
  857.                 // if the path is readable
  858.                 if(is_readable($path))
  859.                 {
  860.                     // we split the new path by directories
  861.                     $subdirectories explode('/',$path);
  862.  
  863.                     // if the new path is a directory
  864.                     if(is_dir($path))
  865.                     {
  866.                     // we scan the new path by calling this function
  867.                      $directory_tree=$this->lsr($path$filter$directory_tree);
  868.  
  869.                     // if the new path is a file
  870.                     }elseif(is_file($path))
  871.                     {
  872.                         // get the file extension by taking everything after the last dot
  873.                         $extension end(explode('.',end($subdirectories)));
  874.  
  875.                         // if there is no filter set or the filter is set and matches
  876.                         if($filter === false || $filter == $extension)
  877.                         {
  878.                          array_push($directory_tree$path)
  879.                         }
  880.                     }
  881.                 }
  882.             }
  883.         }
  884.         // close the directory
  885.         closedir($directory_list)
  886.         // return file list
  887.         if(isset($directory_tree))
  888.         return $directory_tree;
  889.         else return false;
  890.     // if the path is not readable ...
  891.     }else{
  892.         // ... we return false
  893.         return false;    
  894.     }
  895. }
  896. }
  897.  
  898. ?>

Documentation generated on Fri, 16 Oct 2009 09:29:03 +0200 by phpDocumentor 1.4.1