Open Sencillo  2014.008
 All Data Structures Files Functions Variables Pages
files.management.fman.php
Go to the documentation of this file.
1 <?php
12 class filesList
13 {
14  private $files;
15  private $out;
16  protected $path;
17  protected $folderlist;
18 
23  public function __construct($path)
24  {
25  $this->files = scandir($path);
26  $this->path = $path;
27  }
28 
34  public function scanDir($dir='./')
35  {
36  $this->folderlist = array();
37  $this->findFiles($dir, $this->folderlist);
38  return $this->folderlist;
39  }
40 
46  public function findFiles($dir, &$dir_array)
47  {
48  // Create array of current directory
49  $files = scandir($dir);
50 
51  if(is_array($files))
52  {
53  foreach($files as $val)
54  {
55  // Skip home and previous listings
56  if($val == '.' || $val == '..')
57  continue;
58 
59  // If directory then dive deeper, else add file to directory key
60  if(is_dir($dir.'/'.$val))
61  {
62  // Add value to current array, dir or file
63  $dir_array[$dir][] = $val;
64 
65  findFiles($dir.'/'.$val, $dir_array);
66  }
67  else
68  {
69  $dir_array[$dir][] = $val;
70  }
71  }
72  }
73  ksort($dir_array);
74  }
75 
81  public function findFilesStructure($dir)
82  {
83  $result = array();
84 
85  $cdir = scandir($dir);
86  foreach ($cdir as $key => $value)
87  {
88  if (!in_array($value,array(".","..")))
89  {
90  if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
91  {
92  $result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
93  }
94  else
95  {
96  $result[] = $value;
97  }
98  }
99  }
100 
101  return $result;
102  }
103 
111  public function arrayToHtml($style,$folderStyle=null,$ftypes=null,$dot=null)
112  {
113  $i=0;
114  $this->out='';
115 
116  while(sizeof($this->files)>$i)
117  {
118  if(($dot==false)||($dot==null))
119  {
120  if(stristr($this->files[$i],$ftypes)!=false)
121  {
122  //is file
123  if(($this->files[$i]!='.')&&($this->files[$i]!='..'))
124  {
125  $this->out.=$style[0].$this->files[$i++].$style[1];
126  }
127  else
128  {
129  $i++;
130  }
131  }
132  else
133  {
134  //is folder
135  if(($this->files[$i]!='.')&&($this->files[$i]!='..'))
136  {
137  $this->out.=$folderStyle[0].$this->files[$i++].$folderStyle[1];
138  }
139  else
140  {
141  $i++;
142  }
143  }
144  }
145  else
146  {
147  if(is_file($this->files[$i]))
148  {
149  $this->out.=$style[0].$this->files[$i++].$style[1];
150  }
151  else
152  {
153  $this->out.=$folderStyle[0].$this->files[$i++].$folderStyle[1];
154  }
155  }
156  }
157  return $this->out;
158  }
159 }
160 ?>
$result
scanDir($dir='./')
findFiles($dir, &$dir_array)
arrayToHtml($style, $folderStyle=null, $ftypes=null, $dot=null)