Skip to content

Instantly share code, notes, and snippets.

@Bonno
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save Bonno/3fe150808e36105c6262 to your computer and use it in GitHub Desktop.

Select an option

Save Bonno/3fe150808e36105c6262 to your computer and use it in GitHub Desktop.
Delete Directory and Files In Directory
<?php
/*
* PHP delete function that deals with directories recursively
* Snippet from http://www.paulund.co.uk/php-delete-directory-and-files-in-directory
*
* @author Paulund http://www.paulund.co.uk/
* @author Lewis Cowles
*/
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