I want to synchronize two directories. And I use
file_get_contents($source) === file_get_contents($dest)
to compare two files. Is there any problem to do this?
I would rather do something like this:
function files_are_equal($a, $b) { // Check if filesize is different if(filesize($a) !== filesize($b)) return false; // Check if content is different $ah = fopen($a, 'rb'); $bh = fopen($b, 'rb'); $result = true; while(!feof($ah)) { if(fread($ah, 8192) != fread($bh, 8192)) { $result = false; break; } } fclose($ah); fclose($bh); return $result; }
This checks if the filesize is the same, and if it is it goes through the file step by step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With