PHP copy() Function

Definition and Usage

The 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

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

Tips and Comments

Tip:If you need to move a file, please use rename() Function.

Note:Starting from PHP 4.3.0, if "fopen wrappers" are enabled, source and destination can both be URLs. More information can be found in fopen(). If destination is a URL, then if the encapsulating protocol does not support overwriting existing files, the copy operation will fail.

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

Example

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

Output:

1