Jump to content

Different results between md5sum and md5_file


elentz

Recommended Posts

I am trying to get the md5 for a file with using php.  I have a single file in a directory that will change from time to time.  I need to use the md5 result of that file in a config file.  I have a php script that will get the file name and also do the md5 work.  The problem is that the md5_file output is different than the md5sum fo the same file from the cli

<?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;
?> 

Thanks for any idea as to what is going on

Link to comment
Share on other sites

You've shown the code to determine the $md5file value, but what is the value that you are comparing against that does not match and how is that calculated? You state

 

. . . is different than the md5sum fo the same file from the cli

 

Are you sure that the md5sum value is calculated on the actual file and not the file name or path?

Link to comment
Share on other sites

You've shown the code to determine the $md5file value, but what is the value that you are comparing against that does not match and how is that calculated? You state

 

 

Are you sure that the md5sum value is calculated on the actual file and not the file name or path?

 

Now that I have time to think about this.  I think you are right with your last question.  The md5sum is done on the file itself for sure since I ran that from the cli.  The md5_file is probably only doing the path and not the file.  The file will change periodically so I have to use the code to get the file name and use it as a string in the path for the md5_file

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.