Ritesh d joshi Ritesh d joshi - 6 months ago 39
PHP Question

Copy all files from one folder to another Folder using PHP scripts?

Basically, my requirement is, I want to move all files from one folder to another folder using PHP scripts. Any one can help me. I am trying this, but I am getting error

$mydir = dirname( __FILE__ )."/html/images/";
if(!is_dir($mydir)){
mkdir("html/images");
}
// Move all images files
$files = glob("images/*.");
foreach($files as $file){
$file_to_go = str_replace("images/","html/images/",$file);
copy($file, $file_to_go);
}

Answer
// images folder creation using php
   $mydir = dirname( __FILE__ )."/html/images";
   if(!is_dir($mydir)){
   mkdir("html/images");
   }
   // Move all images files
   $files = glob("images/*.*");
   foreach($files as $file){
   $file_to_go = str_replace("images/","html/images/",$file);
         copy($file, $file_to_go);
   }