Skip to content

Instantly share code, notes, and snippets.

@wenpeng
Created January 8, 2016 07:41
Show Gist options
  • Save wenpeng/e47f41d41e1908500c54 to your computer and use it in GitHub Desktop.
Save wenpeng/e47f41d41e1908500c54 to your computer and use it in GitHub Desktop.
删除文件夹下所文件
<?php
function clean_dir($dir, $self = false) {
//先删除目录下的文件:
$dh = opendir($dir);
while ($file = readdir($dh)) {
if($file != '.' && $file !== '..') {
$full_path = $dir .'/'. $file;
if(! is_dir($full_path)) {
unlink($full_path);
} else {
clean_dir($full_path);
}
}
}
closedir($dh);
//删除当前文件夹:
if($self) {
rmdir($dir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment