Is it possible for a PHP file to be deleted at runtime?

I have a PHP install.php "file that handles the installation of other scripts. I want this file to delete itself and the folder containing it after it runs.

Is it possible?

+8
php
source share
2 answers

The demo shows that the folder contains only the install.php file:

mkdir demo cd demo echo "<?php unlink(__FILE__); rmdir(__DIR__); " > install.php php install.php cd .. ls 

That ls no longer displays "demo dir".

Recursive deletion should not be difficult to determine if there are more (sub-) folders you want to delete.

+6
source share

You can use PHP unlink and rmdir to delete the file itself (and its folder). Before deleting the file itself, make sure that you redirect the viewer to another page.

+1
source share

All Articles