-1

I found myself with a huge challenge and I wonder how can I create this, so I've decided to ask for help. This is my problem:

I need a single PHP file that is capable to delete the entire folder and sub folders inside my domain name, that upon deletion, also the file disappears (gets deleted).

I am not sure how to do this, I can show the files under a domain name with a single PHP script, however, it requires me to delete the files by selecting them and then press a delete button to complete my action, I am looking for a PHP script that not also deletes all the files and folders, but can delete itself after completing the task.

Any help is much appreciated, thanks in advance!

  • 1
    `$ echo " test.php` -- `php test.php` – Eakethet Feb 11 '19 at 06:56
  • @Eakethet that sure removes the file, thank you, I forgot about that one. – Pedro Carvalho Feb 11 '19 at 06:59
  • 1
    Possible duplicate of [Delete directory with files in it?](https://stackoverflow.com/questions/3349753/delete-directory-with-files-in-it) – Nick Feb 11 '19 at 06:59
  • @Nick no it is not my friend, to create a file like this I could you also array_map('unlink', glob("$dirname/*.*")); but I want the file to be gone too. Problem is that I make use of .htaccess files and glob function does not delete them :( – Pedro Carvalho Feb 11 '19 at 07:02

3 Answers3

1

This question was being asked before the solution is simple. First, you need to delete all the files with the script and then the folder. Here is the Script that you needed '

https://stackoverflow.com/a/3349792/9638167

This will surely help.

Raja Osama
  • 133
  • 10
1
  1. Put script to any folder
  2. Exec
  3. Folder is delete

rrmdir(__DIR__);

Function implementation in How do I recursively delete a directory and its entire contents (files + sub dirs) in PHP?

FAEWZX
  • 991
  • 7
  • 10
  • 1
    Please don't post answers that just link to another answer. Instead, flag the question for closure as a duplicate of that question. – Nick Feb 11 '19 at 07:09
  • I was thinking about that to be honest. I was intending to create this script to place under a domain name, but sounds risky to have it like that, perhaps I should consider some dependencies, but your idea really helped me in the right path, thank you for contributing. – Pedro Carvalho Feb 11 '19 at 07:09
1

There are several ways to do that. One of them is using exec.

For linux you can use

exec ('rm -rf /path/to/folder');

and for windows you have

exec ('rmdir path/to/folder /S /Q');
Cosmin Staicu
  • 1,809
  • 2
  • 20
  • 27