PHP copy Function
Syntax
copy(source, destination);
Parameter | Description |
Source | $string (file name that you want to copy) |
Destination | $string (file name there you want to copy ) |
Definition and Usage
Copy function is used to copy the content of source file to the destination file.
Note: Destination file data will be lost if already exists. There is no change in source file.
Note: If file not exist then copy function create the file and copy the content of source file to destination (new created file).
Example of copy function
<?php copy('file.txt', 'new-file.txt'); ?>
- Example
- Run
file.txt is the sorce file of that function and new-file.txt file is the destination file of that function.
All the content of the file.txt file will be copy in the new-file.txt file.
Example
<?php $a = copy('uk.txt', 'nuk.txt'); if($a) { echo "Successfully copied" ; } else { echo "Eror occur"; } ?>
Output
You can check file has successfully copied with the help of if else (conditional statement) as mention above.