public static function RecursiveCopyDir($source, $target)
    {
        $source_dir = opendir($source);

        //Check if source directory exists
        if(!$source_dir)
        {
            return false;
        }

        //Create target directory in case it doesnt exist
        if(!file_exists($target))
        {
            self::MakeDir($target, 0755, true);
        }

        while(($item = readdir($source_dir)) !== false)
        {
            $source_full_path = $source . "/" . $item;
            $target_full_path = $target . "/" . $item;

            if($item != "." && $item != "..")
            {
                //copy source files
                if(is_file($source_full_path))
                {
                    if(!copy($source_full_path, $target_full_path))
                    {
                        return false;
                    }
                }
                else if(is_dir($source_full_path))
                {
                    self::RecursiveCopyDir($source_full_path, $target_full_path);
                }
            }
        }

        closedir($source_dir);

        return true;
    }
public static function RecursiveCopyDir($source, $target)
    {
        $source_dir = opendir($source);

        //Check if source directory exists
        if(!$source_dir)
        {
            return false;
        }

        //Create target directory in case it doesnt exist
        if(!file_exists($target))
        {
            self::MakeDir($target, 0755, true);
        }

        while(($item = readdir($source_dir)) !== false)
        {
            $source_full_path = $source . "/" . $item;
            $target_full_path = $target . "/" . $item;

            if($item != "." && $item != "..")
            {
                //copy source files
                if(is_file($source_full_path))
                {
                    if(!copy($source_full_path, $target_full_path))
                    {
                        return false;
                    }
                }
                else if(is_dir($source_full_path))
                {
                    self::RecursiveCopyDir($source_full_path, $target_full_path);
                }
            }
        }

        closedir($source_dir);

        return true;
    }
public static function RecursiveCopyDir ( $ source , $ target ) { $ source_dir = opendir ( $ source ) ; //Check if source directory exists if ( ! $ source_dir ) { return false ; } //Create target directory in case it doesnt exist if ( ! file_exists ( $ target ) ) { self :: MakeDir ( $ target , 0755 , true ) ; } while ( ( $ item = readdir ( $ source_dir ) ) !== false ) { $ source_full_path = $ source . "/" . $ item ; $ target_full_path = $ target . "/" . $ item ; if ( $ item != "." && $ item != ".." ) { //copy source files if ( is_file ( $ source_full_path ) ) { if ( ! copy ( $ source_full_path , $ target_full_path ) ) { return false ; } } else if ( is_dir ( $ source_full_path ) ) { self :: RecursiveCopyDir ( $ source_full_path , $ target_full_path ) ; } } } closedir ( $ source_dir ) ; return true ; }
Copy a directory and its content to another directory replacing any file
on the target directory if already exist.
@param string $source The directory to copy.
@param string $target The copy destination.
@return bool true on success or false on fail.
Copy a directory and its content to another directory replacing any file on the target directory if already exist .