From 1172f71ca8cc22384ab4bf7242c7645d88e0f6c8 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 8 Nov 2014 17:25:31 +0100 Subject: Support multiple files with the same hash Signed-off-by: Florian Pritz --- application/helpers/filebin_helper.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'application/helpers/filebin_helper.php') diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 7adab7279..563364d32 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -324,4 +324,31 @@ function mimetype($file) { return $mimetype; } +function files_are_equal($a, $b) +{ + $chunk_size = 8*1024; + + // 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) && !feof($bh)) { + if (fread($ah, $chunk_size) !== fread($bh, $chunk_size)) { + $result = false; + break; + } + } + + fclose($ah); + fclose($bh); + + return $result; +} + # vim: set noet: -- cgit v1.2.3-24-g4f1b