Home  >  Article  >  Backend Development  >  How to get the md5 sequence value of a directory in PHP

How to get the md5 sequence value of a directory in PHP

WBOY
WBOYOriginal
2016-07-25 08:56:281065browse
This article introduces the method of using PHP code to obtain the md5 sequence value of a directory, and shares a piece of code for the reference of friends in need.

PHP Gets the md5 sequence value of a directory. Code:

<?php
/**
 * 获取目录的 md5 序列值
 * @param string $dir 目录路径
 * @return string
 * @site bbs.it-home.org
 */
if ( ! function_exists('md5_folder'))
{
 function md5_folder ($dir) {

  if (!is_dir($dir)) {
   return false;
  }

  $filemd5s = array();
  $d = dir($dir);

  while (false !== ($entry = $d->read())) {
   if ($entry != '.' && $entry != '..' && $entry != '.svn') {
    if (is_dir($dir.'/'.$entry)) {
     $filemd5s[] = md5_folder($dir.'/'.$entry);
    } else {
     $filemd5s[] = md5_file($dir.'/'.$entry);
    }
   }
  }
  $d->close();
  return md5(implode('', $filemd5s));
 }
}
//相当好用,收藏分享,服务大伙!嘎嘎...
?>


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