SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Location
    The Netherlands
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Copy entire directories with PHP?

    first of all, i'm neither american nor english, but dutch, so my english will be a little bit crapy.
    i'm pretty familiar with html, but not with php. In fact, this is my first attempt, so a little bit help would be great.

    i started a website at wich 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 don't have any experience in PHP, so i started with a simple piece of code:
    Code PHP:
    <?php
    copy_directory('/directory1/','/public/directory1/')
    ?>
    but this doesn't seem to work.
    anyone any suggestions?

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, you can try:

    PHP Code:
    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

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fprins94 View Post
    i want to use cron jobs every night to copy those files to a public directory.
    Why use php? cp -R /path/to/dir /path/to/public/dir

  4. #4
    SitePoint Member
    Join Date
    May 2010
    Location
    The Netherlands
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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: Error


    Path to the script cannot contain any special symbols or whitespaces

    [ Go Back ]

    what am i doing wrong?

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

  5. #5
    SitePoint Member
    Join Date
    May 2010
    Location
    The Netherlands
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    Attached Images Attached Images


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •