PHP copy() function

Definition and Usage

copy() function copies files.

Syntax

copy(source,destination)
Parameter Description
source Required. Specify the file to be copied.
destination Required. Specify the destination of the copied file.

Description

Move file from source Copy to destination. If successful, it returns TRUE, otherwise it returns FALSE.

Tips and Comments

Tip:To move files, please use rename() function.

Comment:Starting from PHP 4.3.0, if "fopen wrappers" are enabled, source and destination can both be URL. More information see fopen(). If destination Is a URL, then if the encapsulation protocol does not support overwriting existing files, the copy operation will fail.

Important Notes:If the target file already exists, it will be overwritten.

Example

<?php
echo copy("source.txt","target.txt");
?>

Output:

1