How to copy a file to another location in PHP?

To copy a file to another location in PHP, you can use the copy() function.

The copy() function takes two parameters: the source file path and the destination file path. Here is an example:

$sourceFile = '/path/to/source/file.txt'; $destinationFile = '/path/to/destination/file.txt'; // Copy the file if (copy($sourceFile, $destinationFile)) { echo "File copied successfully."; } else { echo "Failed to copy the file."; }

Make sure you have the appropriate permissions to read the source file and write to the destination location.