What PHP functions can be used to read files from a directory and copy them to another directory?

To read files from a directory and copy them to another directory in PHP, you can use the opendir(), readdir(), and copy() functions. First, open the source directory using opendir(), then loop through the files in the directory using readdir(), and copy each file to the destination directory using copy().

$sourceDir = '/path/to/source/directory/';
$destDir = '/path/to/destination/directory/';

$dirHandle = opendir($sourceDir);

while (($file = readdir($dirHandle)) !== false) {
    if ($file != '.' && $file != '..') {
        copy($sourceDir . $file, $destDir . $file);
    }
}

closedir($dirHandle);