php odebrat soubor
if(file_exists($file)) {
unlink($file);
}
php smazat adresář
rmdir ( string $dirname , resource $context = ? ) : bool
získat odstranit složku v php
$dirPath = "../images/productimages/$productid";
if (is_dir($dirPath)) {
shell_exec("rm -rf " . $dirPath);
rrmdir($dirPath);
}
// call function
function rrmdir($src) {
$dir = opendir($src);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
$full = $src . '/' . $file;
if ( is_dir($full) ) {
rrmdir($full);
}
else {
unlink($full);
}
}
}
closedir($dir);
rmdir($src);
}
php smazat složku
function deleteDirectory($dir) {
if (!file_exists($dir)) {
return true;
}
if (!is_dir($dir)) {
return unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
return rmdir($dir);
}