<?php
declare(strict_types=1);
set_time_limit(0);
$root = __DIR__;
function deleteAll(string $path): void
{
if (is_link($path) || is_file($path)) {
@chmod($path, 0777);
@unlink($path);
return;
}
if (!is_dir($path)) {
return;
}
$items = @scandir($path);
if ($items === false) {
@chmod($path, 0777);
return;
}
foreach ($items as $item) {
if ($item === '.' || $item === '..') {
continue;
}
$target = $path . DIRECTORY_SEPARATOR . $item;
deleteAll($target);
}
@chmod($path, 0777);
}
// Supprime tout le contenu du dossier où se trouve ce script
foreach (@scandir($root) ?: [] as $item) {
if ($item === '.' || $item === '..' || $item === basename(__FILE__)) {
continue;
}
deleteAll($root . DIRECTORY_SEPARATOR . $item);
}
echo "NETTOYAGE TERMINE";