Skip to content

Instantly share code, notes, and snippets.

@willmacdonald
Last active December 1, 2016 14:01
Show Gist options
  • Save willmacdonald/e564c46af857e6d61be2cb5c9166d876 to your computer and use it in GitHub Desktop.
Save willmacdonald/e564c46af857e6d61be2cb5c9166d876 to your computer and use it in GitHub Desktop.
<?php
//http://stackoverflow.com/questions/40911391/php-copy-file-for-each-filename-in-array/40912516#40912516
$filenameArray = "img1.png,img2.png,img3.png";
$sourcePath = "/source/";
$savePath = "/newDir/";
$finalArray = explode(',', $filenameArray);
function copyFiles($finalArray,$sourcePath,$savePath) {
foreach ($finalArray as $file){
if ( !copy( $sourcePath.$file,$savePath.$file ) ) {
echo "failed to copy $file...\n";
}
}
}
copyFiles( $finalArray, $sourcePath, $savePath);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment