如何使用 PHP 将文件从一个目录复制到另一个目录? [英] How to copy a file from one directory to another using PHP?

查看:44
本文介绍了如何使用 PHP 将文件从一个目录复制到另一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 foo 目录以及 bar 中有一个文件 test.php.如何使用 PHPbar/test.php 替换为 foo/test.php?我使用的是 Windows XP,跨平台解决方案会很棒,但首选 Windows.

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.

推荐答案

你可以使用 复制()函数:

// 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 :

将文件源复制到目的地

如果目的地文件已经存在,它将是覆盖.

这篇关于如何使用 PHP 将文件从一个目录复制到另一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆