Definition :
The copy() function copies a file.
Note: If the to_file file already exists, it will be overwritten.
copy(from_file, to_file, context)
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() |
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.