Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

How to copy all files from one folder to another in PHP?

<?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 by www.tech24qaguide.com #
 
PREVIOUS NEXT
Tagged: #How #copy #files #folder
ADD COMMENT
Topic
Name
8+2 =