// php delete function that deals with directories recursively
// delete_files('/path/for/the/directory/');
// delete the directory also
function delete_files($target)
{
global $dir;
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)) {
if ( $target != "check") unlink( $target);
}
}
// Do not remove current directory
// delete_files("dir_to_remove_content/");
function delete_files($target)
{
global $dir;
if(is_dir($target)){
$files = glob( $target . '*', GLOB_MARK ); //GLOB_MARK adds a slash to directories returned
foreach( $files as $file ) {
delete_files( $file );
}
if ($dir != $target )
rmdir( $target ); // do not remove current directory
} elseif(is_file($target)) {
unlink( $target);
}
}