<?php
/*
* Delete the file or the directory with the files
* If the files have been deleted it returns true, else it returns false
* @path = filename or dirname
*/
function deleteFiles($path) {
//If the filename is a regular file, the function delete it
if(is_file($path)) {
unlink($path);
return true;
}
//Else if the filename is a directory...
elseif(is_dir($path)) {
//Scan the directory, remove '.' and '..'
$scan = scandir($path);
array_shift($scan);
array_shift($scan);
//Remove if the directory is empty
if(empty($scaned)) {
rmdir($path);
return true;
}
//Else, read all files or directories
else {
$file = opendir($path);
while(false !== ($read = readdir($file))) {
$realpath = $path."\\".$read;
//Delete
if($read != '.' && $read != '..') {
deleteFiles($realpath);
}
}
closedir($file);
}
}
//Else return false
else {
return false;
}
}
if(!deleteFiles('C:\wamp\www\Exos&tests\handle\DELETE'))
echo 'failed';
?>
Marche pas, un coup ça me dépasse la mémoire à cause de la fonction récursive, l'autre j'ai des problèmes à cause de ça je crois
//Scan the directory, remove '.' and '..'
$scan = scandir($path);
array_shift($scan);
array_shift($scan);
Si une âme charitable trouve l'erreur 