copy 拷贝文件

发表日期:2021-07-01 08:55:40 | 来源: | | 浏览(720) 分类:文件系统函数

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

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。