Since it is necessary to determine whether the uploaded file has been modified, the md5 value of the uploaded file needs to be recorded. Here is the method of obtaining the md5 value of the file.
Copy code The code is as follows:
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()
The md5_file() function calculates the MD5 hash of a file. The md5() function uses RSA data security, including the MD5 message digest algorithm. Returns the calculated MD5 hash on success, false on failure.
Syntax: md5(string,raw)
Parameter string, required. Specifies the file to be calculated.
Parameter charlist, optional. Specifies hexadecimal or binary output format: TRUE - raw 16-character binary format; FALSE - default. 32-character hexadecimal number.
Copy code The code is as follows:
$filename = "test.txt";
$md5file = md5_file($filename);
echo $md5file;
?>
Store the MD5 hash of the "test.txt" file:
Copy code The code is as follows:
$md5file = md5_file("test.txt");
file_put_contents("md5file.txt",$md5file);
?>
In this example we will detect whether "test.txt" has been changed (i.e. whether the MD5 hash has been changed):
Copy code The code is as follows:
$md5file = file_get_contents("md5file.txt");
if (md5_file("test.txt") == $md5file)
{
echo "The file is ok.";
}
else
{
echo "The file has been changed.";
}
?>
Output:
Copy code The code is as follows:
The file is ok.
http://www.bkjia.com/PHPjc/825398.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825398.htmlTechArticleSince it is necessary to determine whether the uploaded file has been modified, it is necessary to record the md5 value of the uploaded file. Record the file acquisition here. md5 value method. Copy the code The code is as follows: if(isset($_FIL...