copy

(PHP 4, PHP 5, PHP 7, PHP 8)

copy拷貝文件

說明

copy(string $source, string $dest, resource $context = ?): bool

將文件從 source 拷貝到 dest。

如果要移動(dòng)文件的話,請使用 rename() 函數(shù)。

參數(shù)

source

源文件路徑。

dest

目標(biāo)路徑。如果 dest 是一個(gè) URL,則如果封裝協(xié)議不支持覆蓋已有的文件時(shí)拷貝操作會失敗。

警告

如果目標(biāo)文件已存在,將會被覆蓋。

context

A valid context resource created with stream_context_create().

返回值

成功時(shí)返回 true, 或者在失敗時(shí)返回 false。

范例

示例 #1 copy() 例子

<?php
$file 
'example.txt';
$newfile 'example.txt.bak';

if (!
copy($file$newfile)) {
    echo 
"failed to copy $file...\n";
}
?>

參見