由于需要判断上传的文件是否被修改过,需要记录上传文件的md5值,这里记录一下获取文件md5值的方法。
复制代码 代码如下:
if(isset($_FILES['multimedia']) && $_FILES['multimedia']['error']==0)
{
$file_name = $_FILES['multimedia']['name'];
$size = getimagesize($_FILES['multimedia']['tmp_name']);
$type = $_FILES['multimedia']['type'];
$original = $_FILES['multimedia']['tmp_name'];
$md5 = md5_file($original);
echo $md5;
}
md5_file()
md5_file() 函数计算文件的 MD5 散列。md5() 函数使用 RSA 数据安全,包括 MD5 报文摘译算法。如果成功,则返回所计算的 MD5 散列,如果失败,则返回 false。
语法:md5(string,raw)
参数string,必需。规定要计算的文件。
参数charlist,可选。规定十六进制或二进制输出格式:TRUE - 原始 16 字符二进制格式;FALSE - 默认。32 字符十六进制数。
复制代码 代码如下:
$filename = "test.txt";
$md5file = md5_file($filename);
echo $md5file;
?>
存储 "test.txt" 文件的 MD5 散列:
复制代码 代码如下:
$md5file = md5_file("test.txt");
file_put_contents("md5file.txt",$md5file);
?>
在本例中,我们将检测 "test.txt" 是否已被更改(即是否 MD5 散列已被更改):
复制代码 代码如下:
$md5file = file_get_contents("md5file.txt");
if (md5_file("test.txt") == $md5file)
{
echo "The file is ok.";
}
else
{
echo "The file has been changed.";
}
?>
输出:
复制代码 代码如下:
The file is ok.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools
