LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.rm_full_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
45function rm_full_dir(string $directory): bool
46{
47 // If supplied dirname is a file then unlink it
48 if (is_file($directory))
49 {
50 return unlink($directory);
51 }
52 // Empty the folder
53 if (is_dir($directory))
54 {
55 $dir = dir($directory);
56 while ( false !== $entry = $dir->read() )
57 {
58 // Skip pointers
59 if ($entry == '.' || $entry == '..')
60 {
61 continue;
62 }
63 // Deep delete directories
64 if (is_dir($directory . '/' . $entry))
65 {
66 rm_full_dir($directory . '/' . $entry);
67 }
68 else
69 {
70 unlink($directory . '/' . $entry);
71 }
72 }
73 // Now delete the folder
74 $dir->close();
75 return rmdir($directory);
76 }
77 else
78 {
79 return false;
80 }
81}
rm_full_dir(string $directory)