PHP offers many functions for file manipulation. The copy
function copies the contents of one file to another.
The syntax for the copy
function is shown below:
copy(string $source, string $destination, resource $context = ?): bool
The copy
function takes three parameters:
source
: This is a required parameter. source
is the path of the file to be copied to the other file.destination
: This is a required parameter. destination
is the path of the file to which content from the source file will be written.context
: This is an optional parameter. context
specifies a context resource created with stream_context_create()
. The context is determined by what is being passed along (streamed); this means that the situation is unique for different data types.If the file already has content in it, it will be overwritten when it is used as the destination file.
The function returns a bool value; 1
or true
upon success, and 0
or false
in case of errors or failure.
The following code shows how the copy
function works.
Hello,World!
Free Resources