Copy all files from one folder to another Folder using PHP scripts? - Stack Overflow

PHOTO EMBED

Fri Apr 28 2023 05:26:43 GMT+0000 (Coordinated Universal Time)

Saved by @leninzapata #php

// Get array of all source files
$files = scandir("source");
// Identify directories
$source = "source/";
$destination = "destination/";
// 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);
}
content_copyCOPY

https://stackoverflow.com/questions/25780085/copy-all-files-from-one-folder-to-another-folder-using-php-scripts