调用文件以及其父目录来销毁自己?

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";
?>

On a unix-based system: definitely. Use rmdir and unlink. Windows systems tend to lock files that are currently open, so this may not work (although I can't be certain).

Of course, your webserver needs to have full write permissions to the folder, as well as to its parent-folder.

There are a couple of concerns here. First of all you need to make sure that your script has the sufficient access required to delete the files and folders. After that, the problem that I can see within your code is the way you are trying to delete folders. rmdir can delete empty folders only so you need to empty a folder before trying to delete it. It is usually done in a recursive way. Nevertheless, it is a bad idea for a file to remove itself.