如何使用PHP将文件从一个目录复制到另一个目录? [英] How to copy a file from one directory to another using PHP?
本文介绍了如何使用PHP将文件从一个目录复制到另一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
foo
目录中有一个文件 test.php
以及杆
。如何用 bar / test.php
替换 foo / test.php
使用 PHP
?我在Windows XP上,一个跨平台的解决方案会很棒,但是Windows最好。解决方案
你可以使用 copy()
功能: / p>
//将foo / test.php复制到bar / test.php
//如果需要,重写它
copy('foo / test.php','bar / test.php');
从手册页面引用几个相关的句子:
将文件源的副本复制到
dest。
如果目标
文件已经存在,它将被覆盖
。
Say I've got a file test.php
in foo
directory as well as bar
. How can I replace bar/test.php
with foo/test.php
using PHP
? I'm on Windows XP, a cross platform solution would be great but windows preferred.
解决方案
You could use the copy()
function :
// Will copy foo/test.php to bar/test.php
// overwritting it if necessary
copy('foo/test.php', 'bar/test.php');
Quoting a couple of relevant sentences from its manual page :
Makes a copy of the file source to dest.
If the destination file already exists, it will be overwritten.
这篇关于如何使用PHP将文件从一个目录复制到另一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文