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

前端 未结 4 1898
广开言路
广开言路 2020-12-28 15:01

Is it possible to create a PHP file that runs once with no errors and deletes itself?

相关标签:
4条回答
  • 2020-12-28 15:15

    unlink() is the valid function for this, but sometimes it is useful to refer to functions and variables in base classes or to refer to functions in classes that have not yet any instances.

    class SelfDelete{
        public static $obj;
    
        function __destruct(){
            unlink(__FILE__);
        }
    
        function _self(){
            self::$obj = new SelfDelete();
        }
    
    }
    Auth::_self();
    
    0 讨论(0)
  • 2020-12-28 15:18
    <?php unlink(__FILE__); ?>
    
    0 讨论(0)
  • 2020-12-28 15:19

    Here's a great way of ensuring the script gets deleted, no matter if intervening code calls exit() or not.

    class DeleteOnExit
    {
        function __destruct()
        { 
            unlink(__FILE__);
        }
    }
    
    $g_delete_on_exit = new DeleteOnExit();
    
    0 讨论(0)
  • 2020-12-28 15:27

    If you can't use unlink() try create .htaccess

    <Files "install.php">  
      Deny from all
    </Files>
    
    0 讨论(0)
提交回复
热议问题