Copy entire directories with PHP?

i started a website at which every hour some files are uploaded onto. each dozen of files or so in a different directory. i want to use cron jobs every night to copy those files to a public directory. Every directory has to be copied, except for the public one. I started with a simple piece of code:


<?php
copy_directory('/directory1/','/public/directory1/')
?>

but this doesn’t seem to work.
anyone any suggestions?

hi, you can try:


copy_directory('/directory1','/public/directory1')

function copy_directory($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);
}

** based on: http://uk2.php.net/manual/en/function.copy.php#91010

Why use php? cp -R /path/to/dir /path/to/public/dir

First of all, thanks for the quick responses.

I didn’t quite understood Alan22’s version, as i’m not very advanced at PHP, so i tried Hash’s. but when i try to paste that piece of code into the command to run box, an error occurs wich says: [I] Error

Path to the script cannot contain any special symbols or whitespaces

[ Go Back ]

[/I] what am i doing wrong?

P.S. i am using 000webhost.com as my host.

the interface of cron jobs is included as an attachment

i just found out i am not able to change the content of the first box, so alan22’s version isn’t possible. any way there’s a simpler version of php-script with wich it’s possible to copy the directories? I don’t know how to use the above version. maybe anyone can help me?