LEPTON CMS 7.2.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
56function file_list(
57 string $directory,
58 array $skip = [],
59 bool $show_hidden = false,
60 string $file_type = "",
61 string $strip = "",
62 bool $recursive = false
63): array
64{
65 $result_list = [];
66
67 if (is_dir($directory))
68 {
69 $use_skip = !empty($skip);
70
71 $dir = dir($directory);
72 while (false !== ($entry = $dir->read()))
73 {
74 // Skip hidden files
75 if (($entry[0] == '.') && (false === $show_hidden))
76 {
77 continue;
78 }
79 // Check if we to skip anything else
80 if ((true === $use_skip) && (in_array($entry, $skip)))
81 {
82 continue;
83 }
84
85 if (is_file($directory.'/'.$entry))
86 {
87 // Add file to list
88 $temp_file = $directory.'/'.$entry;
89 if ($strip != "")
90 {
91 $temp_file = str_replace($strip, "", $temp_file);
92 }
93
94 if ($file_type === "")
95 {
96 $result_list[] = $temp_file;
97 } else {
98 if (preg_match('/\.'.$file_type.'$/i', $entry))
99 {
100 $result_list[] = $temp_file;
101 }
102 }
103 }
104 else
105 {
106 if (true === $recursive)
107 {
108 $aTemp = file_list($directory.'/'.$entry, $skip, $show_hidden, $file_type, $strip, $recursive);
109 if (!empty($aTemp))
110 {
111 $result_list = array_merge($result_list, $aTemp);
112 }
113 }
114 }
115 }
116 $dir->close();
117 }
118 natcasesort($result_list);
119 return $result_list;
120}
file_list(string $directory, array $skip=[], bool $show_hidden=false, string $file_type="", string $strip="", bool $recursive=false)