-
How to copy files using PHP
To copy files from source folder to destination php provides a copy function. This function takes two arguments, first is source path (source dir) and destination path (destination dir) and copy files from source to destination path.
View Code PHP1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
<?php copyimages($dir,$dirNew); //$dir - source path, $dirNew – destination path //copy files to folder function copyimages($dir,$dirNew){ if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { //exclude unwanted if ($file==".") continue; if ($file=="..")continue; //if ($file=="index.php") continue; for example if you have index.php in the folder copy("$dir/$file","$dirNew/$file"); } closedir($dh); } } } ?>