How To Copy All Files From One Folder To Another

[Solved] How To Copy All Files From One Folder To Another | Php - Code Explorer | yomemimo.com
Question : How to copy all files from one folder to another in PHP?

Answered by : gowri-shankar-balasubramaniam

<?php
function recursive_files_copy($source_dir, $destination_dir)
{ // Open the source folder / directory $dir = opendir($source_dir); // Create a destination folder / directory if not exist @mkdir($destination_dir); // Loop through the files in source directory while($file = readdir($dir)) { // Skip . and .. if(($file != '.') && ($file != '..')) { // Check if it's folder / directory or file if(is_dir($source_dir.'/'.$file)) { // Recursively calling this function for sub directory recursive_files_copy($source_dir.'/'.$file, $destination_dir.'/'.$file); } else { // Copying the files copy($source_dir.'/'.$file, $destination_dir.'/'.$file); } } } closedir($dir);
}
$source_dir = "/home/gowri/folder_1";
$destination_dir = "/home/gowri/folder_2";
recursive_files_copy($source_dir, $destination_dir);
?>

Source : https://www.tech24qaguide.com/php/how-to-copy-all-files-from-one-folder-to-another-in-php/ | Last Update : Wed, 04 May 22

Answers related to how to copy all files from one folder to another in php

Code Explorer Popular Question For Php