假设我在foo
目录和bar
目录中都有一个文件test.php
.如何使用PHP
将bar/test.php
替换为foo/test.php
?我使用的是Windows XP,跨平台的解决方案会很棒,但Windows更受欢迎.
假设我在foo
目录和bar
目录中都有一个文件test.php
.如何使用PHP
将bar/test.php
替换为foo/test.php
?我使用的是Windows XP,跨平台的解决方案会很棒,但Windows更受欢迎.
您可以使用copy()
函数:
// Will copy foo/test.php to bar/test.php
// overwritting it if necessary
copy('foo/test.php', 'bar/test.php');
引用其手册页面中的几句相关句子:
Makes a copy of the file source to dest.
If the destination file already exists, it will be overwritten.