0

I need to check if there is a new version of a photos... first, i need the photo locally. But when the photo is copy locally, the user can update the photo on his server, and i need to check it the photo have change

here is the code

$file1 = file_get_contents($path_photo);
$str1 = strlen($file1);
$file2 = file_get_contents($complete_photo_name);
$str2 = strlen($file2);
if (($str1 == $str2) == false){ <code to take the file on the remote server and copy locally on my server !>}

this code take 9 second for 20 photos.... there should be a faster way to check if two file are the same...both is picture, but maybe there is a new version on the remote server...if there is a new version i need to copy it locally to my server.

p.s i cannot use date, because the date of the photo create locally is never the same as the photo on the remote server !

MORE NOTES : The photos cannot be hotlink to the remote server it must be link locally remote server = somewhere local server = server that execute the code of the web page !

even with md5, it take as much time as copy ans save all the image... what i what is copy only CHANGE images !

NOTE to : This question already has an answer here: It's have NOT been answer... no good or accepted answer... all take too long !

menardmam
  • 9,860
  • 28
  • 85
  • 113
  • You could compare the file hashes by using the `file_hash` function. – MisterBla Feb 11 '15 at 21:12
  • Store a copy of the headers, do a head request, look for file modified and etag. you can also look for size – exussum Feb 11 '15 at 21:13
  • What does it mean to "need the photo locally" - is it stored on the webserver? And what about "when the photo is copy locally"? Are we still on the webserver, or on a client's computer? "can update the photo on his server" is not clear as well. I have a hunch of - and a possible solution to - what you are trying to do, but please fix the grammar and wording first. – John Weisz Feb 11 '15 at 21:16
  • Ask a new question as it does look like you want better performance. – AbraCadaver Feb 11 '15 at 22:16

1 Answers1

1

You better use md5_file function to compare the checksum of each file

Adam
  • 17,838
  • 32
  • 54