PHP copy() Function

PHP copy Function


Definition :

The copy() function copies a file.

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

Syntax

  copy(from_fileto_filecontext)

Parameter 
Parameter Description
from_file Required. Specifies the path to the file to copy from
to_file Required. Specifies the path to the file to copy to
context Optional. Specifies a context resource created with stream_context_create()

Example:

Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to make a copy of this file.

Output :  test.txt is successfully copied as demo.txt.