Last active
December 1, 2016 14:01
-
-
Save willmacdonald/e564c46af857e6d61be2cb5c9166d876 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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