Please answer this question and help me!!
I have found a dozen of code snippets about deleting a folder with its all files and sub folders in PHP. But I am facing difficulties to apply them.
This is an example code :
function rrmdir($path) {
// Open the source directory to read in files
$i = new DirectoryIterator($path);
foreach($i as $f) {
if($f->isFile()) {
unlink($f->getRealPath());
} else if(!$f->isDot() && $f->isDir()) {
rrmdir($f->getRealPath());
}
}
rmdir($path);
}
I can not understand how to write the source directory. I mean, how I set the $path variable? All the files of my website is inside 'public_html' folder. Will I include 'public_html' also?
When I want to delete a folder inside 'usercontent' folder, I am writing like this :
$path = "/usercontent/somefolder"
Please answer with an example directory path.
Update: What should be the permission of the folder which will be deleted.