Php script to copy files to a new folder

I need to set up a script which will take a bunch of files from three different folders and copy them into 1 folder. I do need the files to be copied and not moved.

All the folders involved in this are on the same level.
The image names are all located in a MYSQL database. I will have to set up a query to select the images I need based on a few things but that part should be ok. The bit I don’t know where to start with is actually telling a script what images I want to copy to where and actually getting it to work.

Can anyone tell me how I can go about achieving this please?

As always any help much appreciated, Thanks in advance.


Once you’ve pulled out all the filenames from the db you just need to loop through them and use the ‘rename’ command in PHP (PHP: rename - Manual) if you specify the origin filename (inc path) and the destination (including full path) it will move the file.

You’d have something like:

foreach ($image_name_arr as $image_name) {
rename($source_path.$image, $dest_path.$image);

Hope that helps.

Really appreciate the help with this alexson, I’ll have a go at what you’ve suggested and let you know how I get on. :slight_smile: