많은 유틸리티 함수를 Util, FileUtil, WebUtil로 이동

This commit is contained in:
2018-03-24 22:03:54 +09:00
parent b5cba27df9
commit 157ecdbf2a
36 changed files with 364 additions and 517 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace sammo;
class FileUtil{
public static function delInDir(string $dir) {
$handle = opendir($dir);
if($handle !== false){
while(false !== ($FolderOrFile = readdir($handle))) {
if ($FolderOrFile == "." || $FolderOrFile == "..") {
continue;
}
$filepath = sprintf('%s/%s', $dir, $FolderOrFile);
if (is_dir($filepath)) {
FileUtil::delInDir($filepath);
} // recursive
else {
@unlink($filepath);
}
}
closedir($handle);
}
return true;
}
function delExpiredInDir($dir, $t) {
$handle = opendir($dir);
if ($handle !== false) {
while (false !== ($FolderOrFile = readdir($handle))) {
if ($FolderOrFile == "." || $FolderOrFile == "..") {
continue;
}
$filepath = sprintf('%s/%s', $dir, $FolderOrFile);
if (is_dir($filepath)) {
delExpiredInDir($filepath, $t);
} // recursive
else {
$mt = filemtime($filepath);
if ($mt < $t) {
@unlink($filepath);
}
}
}
closedir($handle);
}
return $success;
}
}