Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何用文件内容替换Web文件内容?_Php - Fatal编程技术网

Php 如何用文件内容替换Web文件内容?

Php 如何用文件内容替换Web文件内容?,php,Php,我有一个名为filecontent.txt的文件,其中包含一些php代码 我还有另一个文件名为index.php 我想用filecontent.txt内容替换index.php内容 有什么解决办法吗 请在这方面帮助我。您可以使用php复制功能 例如: 如果只是替换,您也可以在以后将index.php和filecontent.txt转换为index.php。我需要事先删除,还是php会毫无怨言地覆盖?这与php无关,但与底层文件系统有关。一般来说,你不能将一个文件重命名为另一个文件的名称,所以

我有一个名为filecontent.txt的文件,其中包含一些php代码

我还有另一个文件名为index.php

我想用filecontent.txt内容替换index.php内容

有什么解决办法吗


请在这方面帮助我。

您可以使用php复制功能

例如:



如果只是替换,您也可以在以后将index.php和filecontent.txt转换为index.php。

我需要事先删除,还是php会毫无怨言地覆盖?这与php无关,但与底层文件系统有关。一般来说,你不能将一个文件重命名为另一个文件的名称,所以是的,你需要先删除它。我只想替换包含php标记的完整内容。我不想对单个文件执行此操作,我有许多文件。结果是什么?例外情况是什么?
unlink ("index.php");
rename ("filecontent.txt", "index.php");
unlink ("index.php");
rename ("filecontent.txt", "index.php");