How to sync folders

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tiborv
Forum Newbie
Posts: 11
Joined: Wed May 11, 2005 1:11 am

How to sync folders

Post by tiborv »

Hello !

How can i rsync two folders over the web page ?
What is the command . Only in php or java.

Thanks !
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

This would be a start. Then you could just apply the basic file copy functions within the if-then-else statement of choise...

Code: Select all

<?php
    $dir1 = './1/';
    $dir2 = './2/';
    $arr1 = glob($dir1.'*');
    $arr2 = glob($dir2.'*');
    print_r($arr1); // debugging to...
    print_r($arr2); // ...show example output.

    foreach($arr1 as $file) {
        echo $file .' : '. filemtime($file) .'<br />';
    }
    foreach($arr2 as $file) {
        echo $file .' : '. filemtime($file) .'<br />';
    }
?>
Result:

Code: Select all

Array
(
    &#1111;0] =&gt; ./1/10b.txt
)
Array
(
    &#1111;0] =&gt; ./2/10b.txt
    &#1111;1] =&gt; ./2/alone.txt
)
./1/10b.txt : 1117275238
./2/10b.txt : 1117274932
./2/alone.txt : 1117275000
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

A little sample if you want to sync over ftp
http://timvw.madoka.be/comment.php?message_id=178


But you have asked this question already a few times, and my answer remains the same: Use the right tool for the right job. There are already a zillion of tools to sync (fe: rsync) that are specialized to do this... It would be silly to not use them.
Post Reply