md5 of a file is different using md5_file

Issues related to applications and software problems
edlentz
Posts: 71
Joined: 2013/06/11 20:20:25

md5 of a file is different using md5_file

Postby edlentz » 2018/03/23 20:37:21

I am trying to setup a md5 for a file that will change every so often. I need to use php in order to re-write a config file.

Code: Select all

<?php
   $dir = opendir("/var/www/html/cq_phones/400");
   while (($file = readdir($dir)) !== false) {
   $filename=rtrim($file,".");
   echo $filename;
}
closedir($dir);
$md5file = md5_file("/var/www/html/cq_phones/400/$filename");

echo $md5file;
?>


The md5 text is different using th ephp versus md5sum [filename]

Any idea what is going on?

User avatar
avij
Forum Moderator
Posts: 2453
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: md5 of a file is different using md5_file

Postby avij » 2018/03/23 20:45:25

I would guess that you are md5summing different files.

In any case, worksforme here:

Code: Select all

$ php -r 'echo md5_file("k.txt");'
947210de4db1a4cd8e2689051450c1d6
$ md5sum k.txt
947210de4db1a4cd8e2689051450c1d6  k.txt