Php copy multiple files from one directory to another

The rename function does this

Image rename

rename['image2.jpg', 'newfolder/image2.jpg'];
rename['image4.jpg', 'newfolder/image4.jpg'];
rename['image5.jpg', 'newfolder/image5.jpg'];

If you want to keep the existing file on the same place you should use copy

Image copy

copy['image2.jpg', 'newfolder/image2.jpg'];
copy['image4.jpg', 'newfolder/image4.jpg'];
copy['image5.jpg', 'newfolder/image5.jpg'];

Use Loop for multiple files as below:

//Create an array with image files which should be copy or move in new folder
$files = ['image2.jpg','image4.jpg','image5.jpg'];
foreach[$files as $resFile]{
    rename[$resFile, 'newfolder/'.$resFile];
    copy[$resFile, 'newfolder/'.$resFile];
}

how to copy multiple files from one folder to another in php

Today i will show you how to copy multiple files from one folder to another or same folder.We can easily create a copy or duplicate file to original in PHP with PHP’s built in function called copy[]. It requires two arguments to perform its operation, the source file to copy, and the destination file path. it will return TRUE on Success and FALSE on failure. below i write code for copy multiple files from one folder to another just copy and past and change source file folder path and destination file folder.

PHP code for copy multiple files from one folder to another

Chủ Đề