File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -913,6 +913,38 @@ 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, opt. available disk-space
921+ */
922+
923+ function check_free_space ($ path , $ limit = 0 , &$ free_space = 0 ) {
924+ $ path = rtrim ($ path , '/ ' );
925+
926+ /**
927+ * Make sure that we have only existing directories in the path.
928+
929+ * Given a file name instead of a directory, the behaviour of the disk_free_space
930+ function is unspecified and may differ between operating systems and PHP versions.
931+ */
932+ while (!is_dir ($ path ) && $ path != '/ ' ) $ path = realpath (dirname ($ path ));
933+
934+ $ free_space = disk_free_space ($ out );
935+
936+ if (!$ free_space ) {
937+ $ free_space = 0 ;
938+ return false ;
939+ }
940+
941+ if ($ free_space >= $ limit ) {
942+ return true ;
943+ } else {
944+ return false ;
945+ }
946+
947+ }
916948
917949
918950
You can’t perform that action at this time.
0 commit comments