Home Backend Development PHP Tutorial 利用php失去文件夹的md5校验值

利用php失去文件夹的md5校验值

Jun 13, 2016 pm 01:25 PM
dir entry global md5 str

利用php得到文件夹的md5校验值

<?php /**
 * 工具文件
 * 最终目的在于比较两个文件夹的差异,
 * 
 * 但是本程序只用于得到一个目录的md5校验和,所以需要分别在不同机器上执行,然后比较md5校验和
 * 
 * 
 * 1)调用示例
 * php get_folder_md5.php /home/temp/2 
 * 
 * 2)我不想比.svn目录,所以程序中有$entry != ".svn",如果想彻底比较,请删除&& $entry != ".svn"
 * 3)
 * @author yyy
 */

//参数确定
if (count($argv) > 1 )
  $dir1 = del_postfix($argv[1]);
else 
  die('please input dir');



$global_str = md5('1');  
  
//检查第一个路径有,后者没有或错误的方法。
get_folder_md5($dir1);
echo "===========================================================\n";

echo $global_str;
echo "\n";


/**
 * 去除路径末尾的/,并确保是绝对路径
 *
 * @param unknown_type $dir
 * @return unknown
 */
function del_postfix($dir)
{
    if (!preg_match('#^/#', $dir)) {
        throw new Exception('参数必须是绝对路径');
    }
    $dir = preg_replace('#/$#', '', $dir);
    return $dir;
}




/**
 * 递归调用获取md5
 *
 * @param string $dir1        路径1,是标准
 */
function get_folder_md5($dir1){
    global $global_str;
    if (is_dir($dir1)) {
        $arr =  scandir($dir1);
        foreach ($arr as $entry) {
            if (($entry != ".") && ($entry != "..")  && ($entry != ".svn")){
                $new = $dir1."/".$entry; //$new是完整文件名或文件夹名
                //如果不想显示文件名可以注释下面这句
                echo $entry ."\n";
                $global_str = md5($global_str . $entry);
                if(is_dir($new)) {
                    get_folder_md5($new) ;
                } else { 
                    $global_str = md5($global_str . md5_file($new) );
                }
            }
        }
    }
}

Copy after login
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use MD5 encryption in MySQL How to use MD5 encryption in MySQL May 28, 2023 pm 02:16 PM

What is MD5? MD5 Message-DigestAgorithm (English: MD5Message-DigestAgorithm), a widely used cryptographic hash function, can produce a 128-bit (16-byte) hash value (hash value) to ensure complete and consistent information transmission. MD5 was designed by American cryptographer Ronald Linn Rivest and made public in 1992 to replace the MD4 algorithm. The program of this algorithm is specified in the RFC1321 standard. After 1996, the algorithm was proven to have weaknesses and could be cracked. For data requiring high security, experts generally recommend using other algorithms.

PHP calculates MD5 hash of file PHP calculates MD5 hash of file Mar 21, 2024 pm 01:42 PM

This article will explain in detail about PHP calculating the MD5 hash of files. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP calculates the MD5 hash of a file MD5 (MessageDigest5) is a one-way encryption algorithm that converts messages of arbitrary length into a fixed-length 128-bit hash value. It is widely used to ensure file integrity, verify data authenticity and create digital signatures. Calculating the MD5 hash of a file in PHP PHP provides multiple methods to calculate the MD5 hash of a file: Use the md5_file() function. The md5_file() function directly calculates the MD5 hash value of the file and returns a 32-character

PHP calculates MD5 hash value of string PHP calculates MD5 hash value of string Mar 21, 2024 am 10:51 AM

This article will explain in detail how PHP calculates the MD5 hash value of a string. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Calculating the MD5 hash value of a string in PHP Introduction MD5 (Message Digest 5) is a popular cryptographic hash function used to generate fixed-length hash values, often used to protect data integrity, verify file integrity and Create a digital signature. This article will guide PHP developers on how to use built-in functions to calculate the MD5 hash value of a string. md5() function PHP provides the md5() function to calculate the MD5 hash value of a string. This function receives a string parameter and returns a 32-character hexadecimal hash value.

What is the linux md5 tool What is the linux md5 tool Jun 29, 2023 am 10:51 AM

The linux md5 tool is a tool used to calculate and verify the MD5 hash value of a file. MD5 is a commonly used hash algorithm used to generate a unique, fixed-length hash value, usually 128 bits, in Use the md5sum command in the Linux terminal, and its syntax is "md5sum <file path>".

What are the commonly used shell scripts in Linux? What are the commonly used shell scripts in Linux? Feb 18, 2024 pm 05:36 PM

1. Check the consistency of files in the specified directories of the two servers #!/bin/bash############################## #######Check the consistency of files in the specified directories of the two servers################################ ######By comparing the md5 values ​​of the files on the two servers, the purpose of detecting consistency is achieved. dir=/data/webb_ip=192.168.88.10# Traverse all the files in the specified directory and use them as parameters of the md5sum command. Then get the md5 value of all files and write it to the specified file find$dir-typ

Xiaomi Mesh System AC1200: New Wi-Fi mesh system for up to 370 square meters launches globally Xiaomi Mesh System AC1200: New Wi-Fi mesh system for up to 370 square meters launches globally Jun 19, 2024 pm 12:13 PM

Xiaomi has introduced another WLAN mesh system for the global market. After the AC1200 router (approx. 69 euros on Amazon) went on sale in this country, the Xiaomi Mesh System AC1200 has now been announced. The new product has recently been listed on

How to use Java to calculate the MD5 value of a modified file How to use Java to calculate the MD5 value of a modified file May 29, 2023 am 08:16 AM

What is MD5? MD5 (MessageDigestAlgorithm, message digest algorithm), a widely used cryptographic hash function, can produce a 128-bit (16-byte) hash value (hashvalue) to ensure complete and consistent information transmission. The number 5 after it is because it was invented to replace MD4. Simple understanding, its function is to give the file a unique identifier. If we modify the extension of a file, the file may not be opened, but for MD5, there is no change. So for a file, any renaming is useless for md5 verification. MD5 applications: Here are just a few of the more frequent applications I have seen.

What are the similarities and differences between __str__ and __repr__ in Python? What are the similarities and differences between __str__ and __repr__ in Python? Apr 29, 2023 pm 07:58 PM

What are the similarities and differences between __str__ and __repr__? We all know the representation of strings. Python's built-in function repr() can express objects in the form of strings to facilitate our identification. This is the "string representation". repr() obtains the string representation of an object through the special method __repr__. If __repr__ is not implemented, when we print an instance of a vector to the console, the resulting string may be. >>>classExample:pass>>>print(str(Example()))>>>

See all articles