copy
(PHP 4, PHP 5, PHP 7, PHP 8)
copy — 拷貝檔案
說明
copy(string
$source
, string $dest
, resource $context
= ?): bool
將檔案從 source
拷貝到 dest
。
如果要移動檔案的話,請使用 rename() 函式。
參數
-
source
-
原始檔路徑。
-
dest
-
目標路徑。如果
dest
是一個 URL,則如果封裝協議不支援覆蓋已有的檔案時拷貝操作會失敗。警告如果目標檔案已存在,將會被覆蓋。
-
context
-
A valid context resource created with stream_context_create().
返回值
成功時返回 true
, 或者在失敗時返回 false
。
範例
示例 #1 copy() 例子
<?php
$file = 'example.txt';
$newfile = 'example.txt.bak';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}
?>
參見
- move_uploaded_file() - 將上傳的檔案移動到新位置
- rename() - 重新命名一個檔案或目錄
- The section of the manual about handling file uploads