move all files in a folder to another?
Please try this solution, it's tested successfully ::
<?php $files = scandir("f1"); $oldfolder = "f1/"; $newfolder = "f2/"; foreach($files as $fname) { if($fname != '.' && $fname != '..') { rename($oldfolder.$fname, $newfolder.$fname); } } ?>
A slightly verbose solution:
// 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);
}