Friday, March 29, 2013

copy files one folder to create dyanmic new folder using php


<?php
$ran=rand(125,2212);
copyfolder('bk', $ran);
function copyfolder($source, $destination)
{

       //Open the specified directory

       $directory = opendir($source);

       //Create the copy folder location

      if(!file_exists($destination)){
    mkdir($destination);
 }else{
  echo $destination." floder already exits";
  exit;
 }

       //Scan through the folder one file at a time


       while(($file = readdir($directory)) != false)
       {

              //Copy each individual file

              if(copy($source.'/'.$file,$destination.'/'.$file)){

 }

       }
 
 
$file = $destination.'/index.php';
// Open the file to get existing content
$current = file_get_contents($file);


// Append a new person to the file
$current .= "\nMage::run('$destination', 'website');\n";
// Write the contents back to the file
file_put_contents($file, $current);

}

?>

No comments:

Post a Comment