Quantcast
Channel: php – PHP Web Developer
Viewing all articles
Browse latest Browse all 12

Copy entire contents of a directory into another directory using php

$
0
0

function recursive_copy($src, $dst)
{
    $dir = opendir($src);
    if (!is_dir($dst)) {
        @mkdir($dst);
    }
    while (false !== ($file = readdir($dir))) {
        if (($file != '.') && ($file != '..')) {
            if (is_dir($src . '/' . $file)) {
                recursive_copy($src . '/' . $file, $dst . '/' . $file);
            } else {
                copy($src . '/' . $file, $dst . '/' . $file);
            }
        }
    }
    closedir($dir);
}

I found this function at http://stackoverflow.com/questions/2050859/copy-entire-contents-of-a-directory-to-another-using-php.

Its working perfect !! Try it and leave your comments..

enjoy..


Filed under: php Tagged: php

Viewing all articles
Browse latest Browse all 12

Trending Articles