Copy entire contents of a directory to another using php

php

Question

I tried to copy the entire contents of the directory to another location using

copy ("old_location/*.*","new_location/");

but it says it cannot find stream, true *.* is not found.

Any other way

Thanks Dave

1
133
1/12/2010 5:27:00 PM

It seems that copy only handle single files. Here is a function for copying recursively I found in this note on the copy documentation page:

<?php 
function recurse_copy($src,$dst) { 
    $dir = opendir($src); 
    @mkdir($dst); 
    while(false !== ( $file = readdir($dir)) ) { 
        if (( $file != '.' ) && ( $file != '..' )) { 
            if ( is_dir($src . '/' . $file) ) { 
                recurse_copy($src . '/' . $file,$dst . '/' . $file); 
            } 
            else { 
                copy($src . '/' . $file,$dst . '/' . $file); 
            } 
        } 
    } 
    closedir($dir); 
} 
?>
227
2/1/2015 10:59:40 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon