Search
 
SCRIPT & CODE EXAMPLE
 

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); 
  
?>
Comment

PREVIOUS NEXT
Code Example
Php :: storePublicly laravel with name 
Php :: get original name without mutant model laravel 
Php :: laravel delete file from storage 
Php :: wp_query post count 
Php :: laravel if file is image 
Php :: adding column to array php 
Php :: console php 
Php :: Searching the array for multiple values 
Php :: php add one day to date 
Php :: htmlspecialchars() expects parameter 1 to be string 
Php :: overwrite file php 
Php :: php odd or even 
Php :: laravel mixed content error 
Php :: laravel queue work on shared hosting 
Php :: php code to display current date and time in different formats 
Php :: count() parameter must be an array or an object that implements countable laravel 
Php :: confirm password validation in laravel 
Php :: how to exclude csrf in a route laravel 
Php :: get last month php 
Php :: How To Clear Laravel.Log In Laravel? 
Php :: where laravel function 
Php :: global laravel request() 
Php :: php cookie never expire 
Php :: if else in php html 
Php :: combine date and time in php 
Php :: php echo 
Php :: where_in codeigniter 
Php :: php date format iso 
Php :: change woocommerce return to shop link 
Php :: php multidimensional array get all values by key 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =