If I do:
<?php echo md5(file_get_contents("/path/to/file")) ?>
…will this always produce the same hash as:
<?php echo md5_file("/path/to/file") ?>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes they return the same:
which returns this in my case:
Edit:
Take a look at the source code of both functions: https://github.com/php/php-src/blob/master/ext/standard/md5.c (Line 47 & 76). They both use the same functions to generate the hash except that the
md5_file()function opens the file first.2nd Edit:
Basically the
md5_file()function generates the hash based on the file contents, not on the file meta data like the filename. This is the same waymd5sumon Linux systems work.See this example: