elentz Posted March 23, 2018 Share Posted March 23, 2018 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 23, 2018 Share Posted March 23, 2018 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? Quote Link to comment Share on other sites More sharing options...
elentz Posted March 24, 2018 Author Share Posted March 24, 2018 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.