Last active
December 18, 2015 08:49
-
-
Save paulund/5756951 to your computer and use it in GitHub Desktop.
Delete all files from a directory
This file contains hidden or 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 | |
/* | |
* php delete function that deals with directories recursively | |
*/ | |
function delete_files($target) { | |
if(is_dir($target)){ | |
$files = glob( $target . '*', GLOB_MARK ); //GLOB_MARK adds a slash to directories returned | |
foreach( $files as $file ) | |
{ | |
delete_files( $file ); | |
} | |
rmdir( $target ); | |
} elseif(is_file($target)) { | |
unlink( $target ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment