1

I´ve tried some things now with minor to no success.

What i've tried so far is this:

echo sha1_file("development/index.php")." <- Dev<br>"; // 39e7851f050051abf91eb0791ae6a87084113dd9
echo sha1_file("customer/index.php")." <- Customer"; //17c64da656fae781dd404bbdc10fd2bcb58e12d9

and

echo filesize("development/index.php")." <- Dev<br>"; //369711 
echo filesize("customer/index.php")." <- Customer"; //363338

and this

echo filemtime("development/index.php")." <- Dev<br>"; // 1422516938 
echo filemtime("customer/index.php")." <- Customer"; // 1422516943 

The files are the same - I copied the one from development to customer with filezilla.

I think the sha1_-/md5 didn't work because of the different filetime.

How can I check for sure that the file in the path customer/index.php is the same as in development/index.php ?

For anyone else facing the same problem: The files were not identical!

Solving this problem to make sure the files are really identical:

copy('development/index.php', 'customer/index.php'); // copy file

echo sha1_file("development/index.php")." <- Dev<br>";
echo sha1_file("customer/index.php")." <- Cust<br>";
Top Questions
  • 1,862
  • 4
  • 26
  • 38
  • possible duplicate of [Verifying that two files are identical using pure PHP?](http://stackoverflow.com/questions/18849927/verifying-that-two-files-are-identical-using-pure-php) – Rizier123 Jan 29 '15 at 07:47
  • 3
    Are you sure the file is identical? filesize should be the same for the same file, regardless of its creation or modification times. You might want to take a smaller file, so you can check by hand if it really is different from each other – Markus Müller Jan 29 '15 at 07:47
  • 1
    The files are not the same. Filezilla probably changed the line endings. – Bart Haalstra Jan 29 '15 at 07:47
  • I'm gonna go out on a limb and say they aren't the same – Anthony Jan 29 '15 at 07:47
  • I reuploaded them from disk to both directories and it worked...I made a mistake somewhere...also didn't find the other question but @MarkusMüller pointed at my mistake. Thanks. – Top Questions Jan 29 '15 at 07:53

2 Answers2

2

If both files have different names, and different filetime values, then naturally their hashes will be different. If you want to know whether or not the content of both files is identical, you'll have to compare the hashes of the content, or simply compare the content as a whole:

$contentHash1 = sha1(file_get_contents($file1));
$contentHash2 = sha1(file_get_contents($file2));
echo 'Hash 1: ', $contentHash1, '<br>Hash 2: ', $contentHash2;

If these hashes still don't match, try trim on the content strings (an extra line in one of the files is easy to miss, and make sure the encoding is the same in both files.

Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
  • 2
    This is not true, sha1_file only looks at the content of the file, so `sha1_file($file) == sha1(file_get_contents($file))` – Bart Haalstra Jan 29 '15 at 07:54
  • @BartHaalstra: They're not exactly the same, since `file_get_contents` doesn't use the stream API by default (for that you have to specify a `$context` yourself). `sha1_file` does (and I believe it reads the file in binary mode, `file_get_contents` creates a `zval` string – Elias Van Ootegem Jan 29 '15 at 08:30
0

I think you should try some tool that allows compare by content (for example total commander)

Then look for what are the differences and that will give you some insight why your sha method wasn't working and maybe what else to do if you want to compare files in php.