How can PHP be used to copy files between directories?
To copy files between directories using PHP, you can use the `copy()` function provided by PHP. This function takes two parameters: the source file path and the destination file path. By calling `copy($source, $destination)`, you can easily copy a file from one directory to another.
$source = '/path/to/source/file.txt';
$destination = '/path/to/destination/file.txt';
if (copy($source, $destination)) {
echo "File copied successfully.";
} else {
echo "Failed to copy file.";
}
Keywords
Related Questions
- What are best practices for setting and accessing cookies in PHP to ensure compatibility across different browsers?
- What is the significance of mysql_commit() in PHP when working with transactions in databases?
- How can one ensure that a regular expression pattern in PHP properly matches and replaces specific content without unintended consequences, especially when dealing with special characters like brackets?