functions for file and directory operations moved from functions.common to functions.files and recursive directory removal added

This commit is contained in:
steckbrief 2017-12-28 13:43:46 +01:00
parent b28e7e4125
commit 406f05cd56
2 changed files with 31 additions and 11 deletions

View file

@ -16,17 +16,6 @@ function generate_uuid() {
);
}
function getDirectoryContent($path) {
if (dir_exists($path)) {
return array_diff(scandir($path), array('..', '.'));
}
return [];
}
function dir_exists($path) {
return file_exists($path) && is_dir($path);
}
function format_size($size, $precision = 2) {
$sizes = ['bytes', 'Kb', 'Mb', 'Gb', 'Tb'];
$i = 0;

31
functions.files.inc.php Normal file
View file

@ -0,0 +1,31 @@
<?php
function getDirectoryContent($path) {
if (dir_exists($path)) {
return array_diff(scandir($path), array('..', '.'));
}
return [];
}
function dir_exists($path) {
return file_exists($path) && is_dir($path);
}
function rm_dir($path, $recursive = FALSE) {
if (!dir_exists($path)) {
return TRUE;
}
if ($recursive) {
foreach (getDirectoryContent($path) as $item) {
$itemPath = $path.DIRECTORY_SEPARATOR.$item;
if (dir_exists($itemPath)) {
rm_dir($itemPath, $recursive);
} else {
unlink($itemPath);
}
}
}
return rmdir($path);
}
?>