开发者

Is it possible for a PHP file to delete itself on execution?

开发者 https://www.devze.com 2023-02-15 13:05 出处:网络
I have a PHP file \"install.php开发者_StackOverflow社区\" which handles the installation of other scripts. I want this file to delete itself and its containing folder after it has been run.

I have a PHP file "install.php开发者_StackOverflow社区" which handles the installation of other scripts. I want this file to delete itself and its containing folder after it has been run.

Is this possible?


A demo given that the folder only contains your install.php:

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

The that ls doesn't show the "demo dir" any more.

The recursive deletion shouldn't be that hard to figure out ether if there are more (sub-)folders you want to remove.


You can use PHP unlink and rmdir command to delete the file (and its folder) itself. Make sure you forward the viewer to other page after you delete the file itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消