protected static function xcopy($source, $destination, $permissions = 0755)
    {
        // Check for symlinks
        if (is_link($source)) {
            return symlink(readlink($source), $destination);
        }

        // Simple copy for a file
        if (is_file($source)) {
            return copy($source, $destination);
        }

        // Make destination directory
        if (!is_dir($destination)) {
            mkdir($destination, $permissions);
        }

        // Loop through the folder
        $dir = dir($source);
        while (false !== $entry = $dir->read()) {
            // Skip pointers
            if ($entry == '.' || $entry == '..') {
                continue;
            }

            // Deep copy directories
            self::xcopy(
                $source . DIRECTORY_SEPARATOR . $entry,
                $destination . DIRECTORY_SEPARATOR . $entry
            );
        }

        // Clean up
        $dir->close();
        return true;
    }
protected static function xcopy($source, $destination, $permissions = 0755)
    {
        // Check for symlinks
        if (is_link($source)) {
            return symlink(readlink($source), $destination);
        }

        // Simple copy for a file
        if (is_file($source)) {
            return copy($source, $destination);
        }

        // Make destination directory
        if (!is_dir($destination)) {
            mkdir($destination, $permissions);
        }

        // Loop through the folder
        $dir = dir($source);
        while (false !== $entry = $dir->read()) {
            // Skip pointers
            if ($entry == '.' || $entry == '..') {
                continue;
            }

            // Deep copy directories
            self::xcopy(
                $source . DIRECTORY_SEPARATOR . $entry,
                $destination . DIRECTORY_SEPARATOR . $entry
            );
        }

        // Clean up
        $dir->close();
        return true;
    }
protected static function xcopy ( $ source , $ destination , $ permissions = 0755 ) { // Check for symlinks if ( is_link ( $ source ) ) { return symlink ( readlink ( $ source ) , $ destination ) ; } // Simple copy for a file if ( is_file ( $ source ) ) { return copy ( $ source , $ destination ) ; } // Make destination directory if ( ! is_dir ( $ destination ) ) { mkdir ( $ destination , $ permissions ) ; } // Loop through the folder $ dir = dir ( $ source ) ; while ( false !== $ entry = $ dir -> read ( ) ) { // Skip pointers if ( $ entry == '.' || $ entry == '..' ) { continue ; } // Deep copy directories self :: xcopy ( $ source . DIRECTORY_SEPARATOR . $ entry , $ destination . DIRECTORY_SEPARATOR . $ entry ) ; } // Clean up $ dir -> close ( ) ; return true ; }
Copy a file, or recursively copy a folder and its contents

@param string $source      Source path
@param string $destination Destination path
@param mixed  $permissions New folder creation permissions

@author Benjamin Carl <opensource@clickalicious.de>
@return bool Returns true on success, false on failure
@access protected
Copy a file or recursively copy a folder and its contents