File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments