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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.