Home >php教程 >PHP源码 >md5检验文件

md5检验文件

PHP中文网
PHP中文网Original
2016-05-25 17:09:431488browse

php代码

<?php
//blog.qita.in
echo &#39;md5检验[目录直接md5目录名称,文件就md5_file整个文件的内容]<br>&#39;;
$filename = "test.txt";
if(is_dir($filename)){
    $md5file = md5($filename);
}else{
    $md5file = md5_file($filename);
}
echo $md5file;
 
//保存原始文件的md5值到md5file.txt文件
//file_put_contents("md5file.txt",$md5file);
 
 
//把原始的md5值与现在的md5值比较就可以知道文件是否被修改
$md5file = file_get_contents("md5file.txt");
if (md5_file("test.txt") == $md5file){
    echo "文件正常";
}else{
    echo "文件已经被修改";
}
?>
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