Home » Php » How to Replace a PHP File With an Existing PHP File

How to Replace a PHP File With an Existing PHP File

Posted by: admin February 25, 2020 Leave a comment

Questions:

So currently I have two PHP files, they are identical. There is a function that updates the current file being used to add data and also a clear function. I want the clear function on the first file to replace itself with the content of the second.

How to&Answers:

You can use __FILE__ to get the pathname of the current file, and overwrite this with the second file.

copy("/path/to/second/file.php", __FILE__);