Q: Use files in Folder A if not present in Folder B 2 Folders. Take files from Folder A if not exists in Folder B recursively. 
We have Folder A
fotos
->pic1.png
->pic2.png
theme
->reset.css
->index.php
->folder
->...
index.php
style.css

and Folder B 
where the user saves the individual changes. So the files here vary from 1 to all, eg she/he only changed 2 files:
fotos
->pic1.png
->style.css

Instead of coping the whole folder we want to take the files/folders from folder A if not present in Folder B.
How can this be done recursively and is there a term relating to that? 
i would use RecursiveDirectoryIterator but how: Loading both directories into arrays and than merging with priority to Folder B don't works since they have different indexes. 
In the end, might it be better to just copy the whole folder regarding ressources (space is not so much a problem as memory)?
EDIT: 
Different goal but some parallelities here. could not get it to work so far, thanks for help on answering. I would prefer mod_rewrite ... if it is a valid potential solution ... before using too resource-intense php functions. 
EDIT 2: 
Is this even possible with mod_rewrite? i want to make it dynamically since it should apply for all users.
Structure is as follows or can be changed if necessary:
FOLDER A: 
www/sources/folder A1
www/sources/folder A2
...

FOLDER B: (this are the user's individual Folders)
www/userfiles/folder A1/folder B1
www/userfiles/folder A1/folder B2
...
www/userfiles/folder A2/folder B1
www/userfiles/folder A2/folder B2
...

Thanks for anyone sheding some light ... please.

A: If you have each picture request pointing to a php script outputting them, you could use a simple file_exists statement before trying to output the file.
If you're being really lazy, you could add the two folders in the include path ( http://www.php.net/manual/en/ini.core.php#ini.include-path ) and use file_get contents with the use_include_path flag set to true to load the images. It will try to open the file in one folder first, then the other. Be careful though, because if it doesn't find it in those, it will start looking through the other include folders and some unscrupulous user might try to take advantage of this.

A: get the file on folder A then
go to the path of the folder B
 if(!file_exists($file)){
   //set the path to get the files in the folder or merge the unique files
 }

you can use scan_dir or any other function if you want
