RSK
RSK

Reputation: 17516

Sync files from remote server with php

I am trying to create a desktop app with Php to sync files from remote server.
How can I check whether the file is modified?

First I thought to check the the modified date, But it may result in unwanted upload and download when the file is new on server.

Let a file named sample.txt created in server(modified date:2012-01-24 10:00:00). When I tried to sync this on the next day my app will download it(modified date:2012-01-25 11:00:00). After that when the app check the same folder, it will try to upload the same to server since the file modified date is different in server and in my local system.

So How can I track the changed files something like Dropbox does?

Upvotes: 0

Views: 1332

Answers (2)

scott80109
scott80109

Reputation: 381

If you want to compare 2 files to see if they are identical, then you need to go a little deeper than just comparing the modified date. You should generate a hash for each file, and compare those to see if they are different. If so, then you know the file has changed.

$file1 = md5_file('file1.php');
$file2 = md5_file('file2.php');

if ($file1 != $file2) {
   //file has changed
}

Upvotes: 0

Conrad Shultz
Conrad Shultz

Reputation: 8808

Is there a reason you are looking to write your own (with PHP, no less - hardly a language optimized for use on the desktop)? Why not use, for example, unison, which is designed for exactly what you are requesting?

Upvotes: 3

Related Questions