Recursive Delete.
This function can be used on Windows and *nix based systems :)It will recursively delete every file and folder, in the folder given, and then delete the folder given.
<?php
function RecursiveDelete ( $Location, $Echo = false ) {
if ( $Location{strlen($Location)-1} != '/' ) $Location .= '/';
if ( is_dir($Location) ) {
$FAF = scandir($Location);
for ( $i = 0; $i < count($FAF); $i++ ) {
if ( is_dir($Location.$FAF[$i]) && !in_array($FAF[$i],array('.','..')) ) {
$Done = RecursiveDelete($Location.$FAF[$i],$Echo);
if ( !$Done ) {
if ( $Echo ) echo "Failed whilst deleting Folder($Location{$FAF[$i]}).\n";
return(false);
}
}
elseif ( is_file($Location.$FAF[$i]) ) {
$Done = (unlink($Location.$FAF[$i])?true:false);
if ( !$Done ) {
if ( $Echo ) echo "Failed whilst deleting File($Location{$FAF[$i]}).\n";
return(false);
}
if ( $Echo ) echo "File($Location{$FAF[$i]}) Deleted.\n";
}
}
$Done = (rmdir($Location)?true:false);
if ( $Echo && $Done ) echo "Folder($Location{$FAF[$i]}) Deleted.\n";
return($Done);
} else {
if ( $Echo ) echo "Location($Location) given is not a folder.\n";
return(false);
}
}
RecursiveDelete('',true);
?>