You have to implement a recursive file search which can be done with the PHP: RecursiveDirectoryIterator - Manual
]. Within the iteration check for matching extensions (which can be also done using a filter) and use the PHP: copy - Manual
I suggest to try it yourself using the PHP documentation to increase your skills. Otherwise you can find many examples in the web when breaking down the problem and searching for each part: recursive file search, checking if a file extension (string) matches an item from a list, and copying a file.
Example: Recursive File Search (PHP) - Stack Overflow