removedir retourn un booléen

This commit is contained in:
fredtempez 2021-02-16 18:45:01 +01:00
parent ca5e16d729
commit fdeb89465d
2 changed files with 9 additions and 40 deletions

View File

@ -1009,11 +1009,11 @@ class common {
* @param string URL du dossier à supprimer
*/
public function removeDir ( $path ) {
foreach ( new DirectoryIterator($path) as $item ):
if ( $item->isFile() ) unlink($item->getRealPath());
foreach ( new DirectoryIterator($path) as $item ) {
if ( $item->isFile() ) @unlink($item->getRealPath());
if ( !$item->isDot() && $item->isDir() ) $this->removeDir($item->getRealPath());
endforeach;
rmdir($path);
}
return ( rmdir($path) );
}
/**

View File

@ -43,7 +43,7 @@ class addon extends common {
}
else{
// Suppression des dossiers
if( $this->delete_directory('./module/'.$this->getUrl(2)) === true){
if( $this->removeDir('./module/'.$this->getUrl(2) ) === true){
$success = true;
$notification = 'Module '.$this->getUrl(2) .' effacé du dossier /module/, il peut rester des données dans d\'autres dossiers';
}
@ -65,6 +65,7 @@ class addon extends common {
* Gestion des modules
*/
public function index() {
// Lister les modules
// $infoModules[nom_module]['realName'], ['version'], ['update'], ['delete'], ['dataDirectory']
$infoModules = helper::getModules();
@ -216,7 +217,9 @@ class addon extends common {
// open the source directory
$dir = opendir($src);
// Make the destination directory if not exist
@mkdir($dst);
if (!is_dir($dst)) {
mkdir($dst);
}
// Loop through the files in source directory
while( $file = readdir($dir) ) {
if (( $file != '.' ) && ( $file != '..' )) {
@ -233,40 +236,6 @@ class addon extends common {
closedir($dir);
}
/*
*
* Suppression d'un dossier et de ses sous-dossiers
*/
private function delete_directory($directory, $empty = false) {
if(substr($directory,-1) == "/") {
$directory = substr($directory,0,-1);
}
if(!file_exists($directory) || !is_dir($directory)) {
return false;
} elseif(!is_readable($directory)) {
return false;
} else {
$directoryHandle = opendir($directory);
while ($contents = readdir($directoryHandle)) {
if($contents != '.' && $contents != '..') {
$path = $directory . "/" . $contents;
if(is_dir($path)) {
$this->delete_directory($path);
} else {
unlink($path);
}
}
}
closedir($directoryHandle);
if($empty == false) {
if(!rmdir($directory)) {
return false;
}
}
return true;
}
}
/*
* Création récursive d'un zip
* https://makitweb.com/how-to-create-and-download-a-zip-file-with-php/