サブフォルダを含めてファイル、ディレクトリを削除する。
ただし、ルートディレクトリは消したくないケースがある。
また、ファイルの最終更新日時が1日以上経ったものだけ削除する。
function rmdirEx($rootPath , $dirDelete){
if( !is_dir($rootPath)) return;
$files = scandir($rootPath);
foreach($files as $file){
if ($file == '.' || $file == '..') continue;
$fullpath = $rootPath . DIRECTORY_SEPARATOR . $file;
if(is_dir($fullpath)){
rmdirEx($fullpath , true );
}else{
$lastUpdateTime = filemtime($fullpath);
//更新日時が1日以上前のファイルのみ削除する
if( ($lastUpdateTime + (60 * 60 * 24)) < time())
@unlink($fullpath);
}
}
//消せれば消す
if( $dirDelete) @rmdir($rootPath);
}
