note 113715 added to function.md5-file
| From: | tommuhler at yahoo dot com | Date: | Wed, 20 Nov 2013 16:10:40 +0000 |
| Subject: | note 113715 added to function.md5-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197572@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.md5-file.php
Edit -- https://master.php.net/note/edit/113715
Del: integrated -- https://master.php.net/note/delete/113715/integrated
Del: useless -- https://master.php.net/note/delete/113715/useless
Del: bad code -- https://master.php.net/note/delete/113715/bad+code
Del: spam -- https://master.php.net/note/delete/113715/spam
Del: non-english -- https://master.php.net/note/delete/113715/non-english
Del: in docs -- https://master.php.net/note/delete/113715/in+docs
Del: other reasons-- https://master.php.net/note/delete/113715
Reject -- https://master.php.net/note/reject/113715
Search -- https://master.php.net/manage/user-notes.php