Php 当没有任何更改时,哈希比较为true
我想在两台服务器之间同步文件。 其思想是检查本地服务器上是否存在文件,如果为true,则检查该文件是否与远程服务器相同。如果没有,请更新它。 如果它不存在,请添加它。 代码似乎可以工作,但总是有一个文件被更改,即使没有更改,而且每次都是不同的。 是否存在错误或原因是什么Php 当没有任何更改时,哈希比较为true,php,image,compare,Php,Image,Compare,我想在两台服务器之间同步文件。 其思想是检查本地服务器上是否存在文件,如果为true,则检查该文件是否与远程服务器相同。如果没有,请更新它。 如果它不存在,请添加它。 代码似乎可以工作,但总是有一个文件被更改,即使没有更改,而且每次都是不同的。 是否存在错误或原因是什么 if (file_exists($img)) { $image_hashfile_remote = sha1_file($image_url[$urlIndex]); $image_hashfile_local = sha1_f
if (file_exists($img)) {
$image_hashfile_remote = sha1_file($image_url[$urlIndex]);
$image_hashfile_local = sha1_file($img);
if ($image_hashfile_local == $image_hashfile_remote) {
$num_same++;
} else {
file_put_contents($img, file_get_contents($image_url[$urlIndex]));
echo "Image file as changed since last synchronization. " .$img . " updated. <br />";
echo $image_hashfile_local . " " .$image_hashfile_remote . "<br />";
$num_saved++;
}
} else {
file_put_contents($img, file_get_contents($image_url[$urlIndex]));
echo "New image file found. " . $img . " added. <br />";
$num_saved++;
}
在对可能不存在的文件执行sha1_文件后,您正在测试file_exists$img,这不是很奇怪吗?好吧,这也许不是最好的说法,但有道理。