public static function clearDirectory($path)
{
if (!file_exists($path)) {
return null;
}
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $fileinfo) {
// if the file isn't a .gitignore file we should remove it.
if ($fileinfo->getFilename() !== '.gitignore') {
$todo = $fileinfo->isDir() ? 'rmdir' : 'unlink';
$todo($fileinfo->getRealPath());
}
}
// since the folder now contains a .gitignore we can't remove it
//rmdir($path);
return true;
}