Created
January 8, 2016 07:41
-
-
Save wenpeng/e47f41d41e1908500c54 to your computer and use it in GitHub Desktop.
删除文件夹下所文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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