Home  >  Article  >  Backend Development  >  A PHP file that should be run once and automatically delete itself. Is this possible?

A PHP file that should be run once and automatically delete itself. Is this possible?

WBOY
WBOYforward
2023-08-28 23:01:06752browse

A PHP file that should be run once and automatically delete itself. Is this possible?

Yes, it can be done using the unlink function. As shown below -

<?php unlink(__FILE__); ?>

Another alternative way to delete the script, whether or not the exit function is called, as shown below ^minus;

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

The above is the detailed content of A PHP file that should be run once and automatically delete itself. Is this possible?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete