This post was updated 649 days ago and some of the ideas may be out of date.

原理:遍历获取目录下所有文件的md5序列值连接在一起再次计算md5值。

<?php

/**
 * Created by PhpStorm.
 * User: LinFei
 * Created time 2022/9/11 09:25:01
 * E-mail: 2453095588@qq.com
 */
declare (strict_types=1);

/**
 * 获取文件夹MD5序列值
 * @param string $folder 文件夹路径
 * @return false|string
 */
function md5_folder(string $folder)
{
    if (!is_dir($folder)) {
        return false;
    }

    $md5 = '';

    $items = new \FilesystemIterator($folder);

    /** @var \SplFileInfo $item */
    foreach ($items as $item) {
        if ($item->isFile()) {
            $md5 .= md5_file($item->getPathname());
        }
    }

    return md5($md5);
}