PHP file that should run once and delete itself. Is it possible?

PHPServer Side ProgrammingProgramming

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();
raja
Published on 07-Apr-2020 11:13:16
Advertisements