Skip to content

Instantly share code, notes, and snippets.

@paulund
Last active December 18, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulund/5756951 to your computer and use it in GitHub Desktop.
Save paulund/5756951 to your computer and use it in GitHub Desktop.
Delete all files from a directory
<?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