LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.scan_current_dir.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
50function scan_current_dir(string $root = '', string $file_type = '' ): array
51{
52 $FILE = array(
53 'path' => array(),
54 'filename' => array()
55 );
56
57 if ($root == '')
58 {
59 $root = getcwd();
60 }
61
62 if (false !== ($handle = dir($root)))
63 {
64 // Loop through the files and dirs an add to list
65 while (false !== ($file = $handle->read()))
66 {
67 if (($file[0] != '.') && ($file != 'index.php'))
68 {
69 if (is_dir( $root . '/' . $file))
70 {
71 $FILE[ 'path' ][] = $file;
72 }
73 else
74 {
75 if ($file_type === '')
76 {
77 $FILE[ 'filename' ][] = $file;
78 }
79 else
80 {
81 if (preg_match('/\.'.$file_type.'$/i', $file))
82 {
83 $FILE[ 'filename' ][] = $file;
84 }
85 }
86 }
87 }
88 }
89 $handle->close();
90 }
91
92 natcasesort( $FILE[ 'path' ] );
93 natcasesort( $FILE[ 'filename' ] );
94 $FILE['path'] = array_merge([], $FILE['path']);
95 $FILE['filename'] = array_merge([], $FILE['filename']);
96 return $FILE;
97}
scan_current_dir(string $root='', string $file_type='')