php copy 函数使用 【转】

copy

(PHP 4, PHP 5, PHP 7)

copy—拷贝文件

说明

copy(string$source,string$dest[,resource$context] ) :bool

将文件从source拷贝到dest

如果要移动文件的话,请使用rename()函数。

参数

source

源文件路径。

dest

目标路径。如果dest是一个 URL,则如果封装协议不支持覆盖已有的文件时拷贝操作会失败。

Warning

如果目标文件已存在,将会被覆盖。

context

A valid context resource created withstream_context_create().

返回值

成功时返回TRUE, 或者在失败时返回FALSE

更新日志

版本 说明
5.3.0 增加了对 context 的支持。
4.3.0 如果启用了“fopen wrappers”的话,sourcedest都可以是 URL。更多细节见fopen()

范例

Example #1copy()例子

<?php  
$file = 'example.txt';  
$newfile = 'example.txt.bak';  
  
if (!copy($file, $newfile)) {  
    echo "failed to copy $file...
";  
}  
?>

参见

文章来自:https://www.php.net/manual/zh/function.copy.php

原文地址:https://www.cnblogs.com/KillBugMe/p/13118273.html