The copy() function in PHP is used to copy a file from source to target or destination directory. It makes a copy of the source file to the destination file and if the destination file already exists, it gets overwritten. The copy() function returns true on success and false on failure.
bool copy( string $source, string $destination, resource $context )
Parameters: This function uses three parameters source, destination and context which are listed below:
- $source: It specifies the path of the source file.
- $destination: It specifies the path of the destination file or folder.
- $context: It specifies the context resource created with stream_context_create() function. It is optional parameter.
Return: It returns a boolean value, either true (on success) or false (on failure).
Input : $source = 'Source_file_location' $destination = 'Destination_file_location' copy( $source, $destination ) Output: true
File has been copied!
- Copy the entire contents of a directory to another directory in PHP
- Perl | Accessing a Directory using File Globbing
- Python program to reverse the content of a file and store it in another file
- How to check the given path is file or directory in node.js ?
- Shallow Copy and Deep Copy in C#
- How to include one CSS file in another?
- How to copy the content of a div into another div using jQuery ?
- How to count files in a directory using PHP?
- How to get names of all the subfolders and files present in a directory using PHP?
- How to copy a map to another map in Golang?
- Copy an Array by Value and Reference into Another Array in Golang
- PHP | dir() (Get instance of the Directory)
- How to include() all PHP files from a directory ?
- How to create directory with HTML button and PHP ?
- How to Zip a directory in PHP?
- How to recursively delete a directory and its entire contents (files + sub dirs) in PHP?
- Why PHP script does not create a directory with 777 permissions ?
- PHP append one array to another
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.