(PHP 4, PHP 5)
copy — 拷貝文件
說明
bool copy ( string$source
, string $dest
[, resource $context
] )
將文件從 source
拷貝到 dest
。
如果要移動文件的話,請使用 rename() 函數。
參數
source
源文件路徑。
dest
目標路徑。如果 dest
是一個 URL,則如果封裝協議不支持覆蓋已有的文件時拷貝操作會失敗。
如果目標文件已存在,將會被覆蓋。
context
A valid context resource created with stream_context_create().
返回值
成功時返回 TRUE
, 或者在失敗時返回 FALSE
。
更新日志
版本
說明
5.3.0
增加了對 context 的支持。
4.3.0
如果啟用了“fopen wrappers”的話,source
和
dest
都可以是 URL。更多細節見 fopen()。
范例
Example #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