getMTime()] = $fileinfo->getFilename(); } krsort($files); foreach($files as $file) { if (!in_array($file, $blackList)) { if($cpt++ >= $_nbFiles){ $return = (unlink($_path . $file)) ? TRUE : FALSE; } } } return $return; } public static function cleanFilesByTime(string $_path, int $_limitTime = 24*3600) // 24*3600 pour une journée { if ($handle = opendir($_path)) { while (false !== ($file = readdir($handle))) { $filelastmodified = filemtime($_path . $file); if((time() - $filelastmodified) > $_limitTime) { unlink($_path . $file); } } closedir($handle); } } public static function compress(string $_file){ $command = "gzip " . $_file; try { system($command); return $_file.".gz"; } catch (Exception $ex) { return FALSE; } } public static function decompress(string $_zip, bool $_delete = FALSE){ $command = "gunzip " . $_zip; try { system($command); ($_delete == TRUE) ? unlink($_zip) : ""; return explode(".gz", $_zip)[0]; } catch (Exception $ex) { return FALSE; } } public static function copyFolder(string $_folder, string $_target) { if($dir = opendir($_folder)){ mkdir($_target); while (($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { if (is_dir($_folder . '/' . $file)) { self::copyFolder($_folder . '/' . $file, $_target . '/' . $file); } else { copy($_folder . '/' . $file, $_target . '/' . $file); } } } closedir($dir); } } }