PHP File That Runs Once and Deletes Itself



Yes, it can be done using the unlink function. It has been shown below −

<?php unlink(__FILE__); ?>

Another alternative that deletes the script irrespective of whether the exit function is called or not, has been shown below ^minus;

class DeleteOnExit {
   function __destruct() {
      unlink(__FILE__);
   }
}
$delete_on_exit = new DeleteOnExit();
AmitDiwan
AmitDiwan

Updated on: 2020-04-07T11:13:40+05:30

269 Views

Kickstart Your Career

Get certified by completing the course

Get Started