PHP gets the MD5 value of the file and determines whether the example is modified _php tutorial

Source: Internet
Author: User
Tags md5 hash
Since it is necessary to determine if the uploaded file has been modified, the MD5 value of the uploaded file needs to be recorded, and the method of obtaining the MD5 value of the file is recorded here.

Copy the Code code 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 '];
$MD 5 = md5_file ($original);
echo $MD 5;
}

Md5_file ()

The Md5_file () function computes the MD5 hash of the file. The MD5 () function uses RSA data security, including the MD5 message selected passage algorithm. If successful, returns the computed MD5 hash, or False if it fails.

Syntax: MD5 (STRING,RAW)

Parameter string, required. Specify the documents to be calculated.

Parameter charlist, optional. Specify hexadecimal or binary output format: TRUE-original 16 character binary format; FALSE-Default. 32 character hexadecimal number.

Copy the Code code as follows:
<?php
$filename = "Test.txt";
$MD 5file = Md5_file ($filename);
echo $MD 5file;
?>

To store the MD5 hash of the "test.txt" file:

Copy the Code code as follows:
<?php
$MD 5file = md5_file ("test.txt");
File_put_contents ("Md5file.txt", $md 5file);
?>

In this example, we will detect if "test.txt" has been changed (that is, if the MD5 hash has been changed):
Copy the Code code as follows:
<?php
$MD 5file = file_get_contents ("Md5file.txt");
if (Md5_file ("test.txt") = = $md 5file)
{
echo "The file is OK.";
}
Else
{
echo "The file has been changed.";
}
?>

Output:
Copy the Code code as follows:
The file is OK.

http://www.bkjia.com/PHPjc/825398.html www.bkjia.com true http://www.bkjia.com/PHPjc/825398.html techarticle since it is necessary to determine if the uploaded file has been modified, the MD5 value of the uploaded file needs to be recorded, and the method of obtaining the MD5 value of the file is recorded here. Copy the code code as follows: if (Isset ($_fil ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.