Monday, January 30, 2017

Move all file from a folder to another PHP

// Get array of all source files into source_folder
$files = scandir("source_folder");

// Identify directories inside source_folder
$source = "source_folder/";
$destination = "destination_folder/";

// Cycle through all source files
foreach ($files as $file) {
  if (in_array($file, array(".",".."))) continue;
  // If we copied this successfully, mark it for deletion
  if (copy($source.$file, $destination.$file)) {
    $delete[] = $source.$file;
  }
}
// Delete all successfully-copied files
foreach ($delete as $file) {
  unlink($file);

}

If we want to copy all files from a folder to another follow this URL; http://programming-scripts.blogspot.com/2017/01/copy-all-file-from-folder-to-another-php.html

No comments:

Post a Comment