PHP: getting the md5 code of the uploaded file _ PHP Tutorial

Source: Internet
Author: User
Tags md5 hash
PHP obtains the md5 code of the uploaded file. To determine whether the uploaded file has been modified, you need to record the md5 value of the uploaded file. here, record the method for obtaining the md5 value of the file. If (isset ($ _ FILES [multimedia]) $ _ FILES [to determine whether the uploaded file has been modified, you need to record the md5 value of the uploaded file, here we record how to obtain the md5 value of a file.

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 hash of the md5_file () function compute file. The md5 () function uses RSA Data Security, including the MD5 packet excerpt algorithm. If the calculation succeeds, the calculated MD5 hash is returned. if the calculation fails, false is returned.

Syntax: md5 (string, raw)

  • The string parameter, required. Specifies the file to be calculated.
  • The charlist parameter. optional. The hexadecimal or binary output format is required: TRUE-original 16-character binary format; FALSE-default. 32 characters in hexadecimal notation.
 

MD5 hash for storing the "test.txt" file:

 

In this example, we will check whether "test.txt" has been changed (that is, whether the MD5 hash has been changed ):

   

Output:

The file is ok.

Bytes. If (isset ($ _ FILES ['multimedia ']) $ _ FILES ['...

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.