try this will remove the folder
and its content
(subfolders
)
system('/bin/rm -rf ' . escapeshellarg($dir));
where $dir
is the path of folder
Domanda
All functions works except the removeIt one (blank page). Here is my code bellow :
class Dir {
public function emptyIt($path) {
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_file($path."/".$file)) {
unlink($path."/".$file);
} else {
if($handle2 = opendir($path."/".$file)) {
while (false !== ($file2 = readdir($handle2))) {
if ($file2 != "." && $file2 != "..") {
unlink($path."/".$file."/".$file2);
}
}
}
rmdir($path."/".$file);
}
}
}
}
return true;
}
function isEmpty($path) {
$handle=opendir($path);
$i=0;
while (false !== ($file = readdir($handle))) {
$i++;
}
closedir($handle);
if($i>=2) {
return false;
} else {
return true;
}
}
public function removeIt($path) {
if (emptyIt($path)) {
if (rmdir($path)) {
return true;
} else {
return false;
}
}
}
}
I have 3 functions to make it work :
isEmpty
: verify if the folder is emptyemptyIt
: empty folder and subfoldersremoveIt
: remove folderAny hint ?
Soluzione
try this will remove the folder
and its content
(subfolders
)
system('/bin/rm -rf ' . escapeshellarg($dir));
where $dir
is the path of folder
Altri suggerimenti
Maybe you execute the program with a user that doesn't have the permissions to make changes on the folder, try executing it with root or give permissions to the current user, good luck.
try this will not
remove the empty
direcotires
from php.net
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}