Skip to content

Commit 6ff8d7b

Browse files
author
Florian Schaal
committed
add function to check the free space for a given directory
1 parent d73ce64 commit 6ff8d7b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

server/lib/classes/system.inc.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,43 @@ function checkpath($path) {
913913
}
914914

915915

916+
/**
917+
* This function checks the free space for a given directory
918+
* @param path check path
919+
* @param limit min. free space in bytes
920+
* @return bool - true when the the free space is above limit ohterwise false
921+
*/
922+
923+
function check_free_space($path, $limit = 0) {
924+
$path = rtrim($path, '/');
925+
$parts = explode('/', $path);
926+
$out = '';
927+
928+
/**
929+
* Make sure that we have only existing directories in the path.
930+
931+
* Given a file name instead of a directory, the behaviour of the disk_free_space
932+
function is unspecified and may differ between operating systems and PHP versions.
933+
*/
934+
for ($i = 1; $i < count($parts); $i++) {
935+
if ( !is_file($out.'/'.$parts[$i]) && is_dir($out.'/'.$parts[$i]) ) {
936+
$out .= '/'.$parts[$i];
937+
}
938+
}
939+
940+
unset($parts);
941+
942+
$res = disk_free_space($out);
943+
944+
if (!$res) return false;
945+
946+
if ($res >= $limit) {
947+
return true;
948+
} else {
949+
return false;
950+
}
951+
952+
}
916953

917954

918955

0 commit comments

Comments
 (0)