LEPTON CMS 7.0.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.file_list.php
Go to the documentation of this file.
1<?php
2
18// include secure.php to protect this file and the whole CMS!
19if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
20if (defined('LEPTON_PATH')) {
21 include LEPTON_PATH.SEC_FILE;
22} else {
23 $oneback = "../";
24 $root = $oneback;
25 $level = 1;
26 while (($level < 10) && (!file_exists($root.SEC_FILE))) {
27 $root .= $oneback;
28 $level += 1;
29 }
30 if (file_exists($root.SEC_FILE)) {
31 include $root.SEC_FILE;
32 } else {
33 trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
34 }
35}
36// end include secure file
37
38
57function file_list(
58 string $directory,
59 array $skip = [],
60 bool $show_hidden = false,
61 string $file_type = "",
62 string $strip = "",
63 bool $recursive = false
64): array
65{
66 $result_list = [];
67
68 if (is_dir($directory))
69 {
70 $use_skip = !empty($skip);
71
72 $dir = dir($directory);
73 while (false !== ($entry = $dir->read()))
74 {
75 // Skip hidden files
76 if (($entry[0] == '.') && (false === $show_hidden))
77 {
78 continue;
79 }
80 // Check if we to skip anything else
81 if ((true === $use_skip) && (in_array($entry, $skip)))
82 {
83 continue;
84 }
85
86 if (is_file($directory.'/'.$entry))
87 {
88 // Add file to list
89 $temp_file = $directory.'/'.$entry;
90 if ($strip != "")
91 {
92 $temp_file = str_replace($strip, "", $temp_file);
93 }
94
95 if ($file_type === "")
96 {
97 $result_list[] = $temp_file;
98 } else {
99 if (preg_match('/\.'.$file_type.'$/i', $entry))
100 {
101 $result_list[] = $temp_file;
102 }
103 }
104 }
105 else
106 {
107 if (true === $recursive)
108 {
109 $aTemp = file_list($directory.'/'.$entry, $skip, $show_hidden, $file_type, $strip, $recursive);
110 if (!empty($aTemp))
111 {
112 $result_list = array_merge($result_list, $aTemp);
113 }
114 }
115 }
116 }
117 $dir->close();
118 }
119 natcasesort($result_list);
120 return $result_list;
121}
file_list(string $directory, array $skip=[], bool $show_hidden=false, string $file_type="", string $strip="", bool $recursive=false)