note 113715 deleted from function.md5-file by sobak

From: Date: Thu, 17 Nov 2016 06:27:22 +0000
Subject: note 113715 deleted from function.md5-file by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207128@lists.php.net to get a copy of this message
Note Submitter: tommuhler at yahoo dot com ---- Sorry for voting Chris's code down. It is great, but there are some brackets missing. If you add more complex conditions than just a mere echo in the top IF ... ELSE structure please include the curly braces ... otherwise php will choke. <?php define('READ_LEN', 4096); if(files_identical('file1.txt', 'file2.txt')) { echo 'files identical'; } else { echo 'files not identical'; } // pass two file names // returns TRUE if files are the same, FALSE otherwise function files_identical($fn1, $fn2) { if(filetype($fn1) !== filetype($fn2)) return FALSE; if(filesize($fn1) !== filesize($fn2)) return FALSE; if(!$fp1 = fopen($fn1, 'rb')) return FALSE; if(!$fp2 = fopen($fn2, 'rb')) { fclose($fp1); return FALSE; } $same = TRUE; while (!feof($fp1) and !feof($fp2)) if(fread($fp1, READ_LEN) !== fread($fp2, READ_LEN)) { $same = FALSE; break; } if(feof($fp1) !== feof($fp2)) $same = FALSE; fclose($fp1); fclose($fp2); return $same; } ?>

« previous php.notes (#207128) next »