I have a little project I'm working on, and have a little bit of an issue. I have a directory called "actions", and inside this folder I have a PHP file named "remove.php".
I'm trying to make it so when I call the "remove.php" file from outside the "actions" folder, the folder "actions" along with all contents are deleted. But can't seem to get it working since the file I'm calling to do the deletion is inside that "actions" directory.
Pretty much I'm wanting to call upon a file to destroy itself along with its parent directory.
Is this possible? I'm programming in PHP BTW.
Thanks in advance for any help.
This is my "remove.php" files code:
<?php
// Get parent folder
$parent = basename(dirname($_SERVER['PHP_SELF']));
// Loop through all files and folders, and remove them
foreach(glob($parent . '/*') as $file)
{
if(is_dir($file))
{
rmdir($file);
} else
{
unlink($file);
}
}
// Remove parent folder after all files have been deleted
rmdir($parent);
// Inform that folder has been deleted
echo "actions folder deleted";
?>