Home  >  Article  >  Backend Development  >  PHP implements md5 inspection file

PHP implements md5 inspection file

WBOY
WBOYOriginal
2016-07-25 08:42:051627browse

[PHP] Code

  1. //blog.qita.in
  2. echo 'md5 check [directory md5 directory name, file is md5_file entire file content]
    ';
  3. $filename = "test.txt";
  4. if(is_dir($filename)){
  5. $md5file = md5($filename);
  6. }else{
  7. $md5file = md5_file($filename);
  8. }
  9. echo $md5file ;
  10. //Save the md5 value of the original file to the md5file.txt file
  11. //file_put_contents("md5file.txt",$md5file);
  12. //Compare the original md5 value with the current md5 value to know the file Whether it has been modified
  13. $md5file = file_get_contents("md5file.txt");
  14. if (md5_file("test.txt") == $md5file){
  15. echo "The file is normal";
  16. }else{
  17. echo "The file has been modified Modify";
  18. }
  19. ?>
Copy code
PHP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn