Ultimele tutoriale de dezvoltare web
 

PHP md5_file() Function

<PHP String Reference

Exemplu

Se calculează MD5 hash al fișierului text "test.txt" :

<?php
$filename = "test.txt";
$md5file = md5_file($filename);
echo $md5file;
?>

Ieșirea codului de mai sus va fi:

d41d8cd98f00b204e9800998ecf8427e


Definiție și utilizare

md5_file() funcția calculează MD5 hash a unui fișier.

md5_file() funcția utilizează RSA Data Security, Inc. MD5 Message-Digest algoritm.

De la RFC 1321 - MD5 Message-Digest algoritm: "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." de "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." în "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." în "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." , "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." - "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." de a "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." în "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." , "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA."

Pentru a calcula hash MD5 al unui șir de caractere, utilizați md5() funcția.


Sintaxă

md5_file( file,raw )

Parametru Descriere
file Necesar. Fișierul care urmează să fie calculate
raw Opțional. O valoare boolean care specifică hex sau formatul de ieșire binar:
  • TRUE - Raw 16 caractere format binar
  • FALSE - implicit. numărul hexazecimal de 32 de caractere

Detalii tehnice

Întoarcere Valoare: Returnează hash MD5 calculat pe un succes, sau FALSE în caz de eșec
Versiune PHP: 4.2.0+
Changelog: Parametrul brut a fost adăugat în PHP 5.0

Ca de PHP 5.1, este posibil să se utilizeze md5_file() cu ambalaje, de exemplu , md5_file("http://w3ii.com/..")

Mai multe exemple

Exemplul 1

Păstrați hash MD5 "test.txt" într - un fișier:

<?php
$md5file = md5_file("test.txt");
file_put_contents("md5file.txt",$md5file);
?>

Testul în cazul în care "test.txt" a fost modificat ( în cazul în care este hash MD5 a fost modificat):

<?php
$md5file = file_get_contents("md5file.txt");
if (md5_file("test.txt") == $md5file)
  {
  echo "The file is ok.";
  }
else
  {
  echo "The file has been changed.";
  }
?>

Ieșirea codului de mai sus ar putea fi:

The file is ok.


<PHP String Reference