Neueste Web-Entwicklung Tutorials
 

PHP md5_file() Function

<PHP String Referenz

Beispiel

Berechnen Sie den MD5 - Hash der Textdatei "test.txt" :

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

Der Ausgang des Code oben wird sein:

d41d8cd98f00b204e9800998ecf8427e


Definition und Verwendung

Die md5_file() Funktion berechnet die MD5 - Hash einer Datei.

Die md5_file() Funktion verwendet die RSA Data Security, Inc. MD5 Message-Digest Algorithm.

Von RFC 1321 - Der MD5 Message-Digest Algorithm: "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." - "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." bei "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." sie "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."

Um den MD5 Hash einer Zeichenfolge zu berechnen, verwenden die md5() Funktion.


Syntax

md5_file( file,raw )

Parameter Beschreibung
file Erforderlich. Die Datei berechnet werden
raw Optional. Ein Boolescher Wert, hex oder binäres Ausgabeformat angibt:
  • TRUE - Raw 16 Zeichen Binärformat
  • FALSCH - Standard. 32 Zeichen Hexadezimalzahl

Technische Details

Rückgabewert: Gibt den berechneten MD5-Hash bei Erfolg oder FALSE bei einem Fehler
PHP Version: 4.2.0+
Änderungsprotokoll: Der rohe Parameter wurde in PHP 5.0 hinzugefügt

Ab PHP 5.1 ist es möglich , verwenden md5_file() mit Wrapper, zB md5_file("http://w3ii.com/..")

Mehr Beispiele

Beispiel 1

Lagern Sie den MD5 - Hash "test.txt" in einer Datei:

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

Testen Sie, ob "test.txt" geändert wurde (das heißt , wenn der MD5 - Hash geändert wurde):

<?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.";
  }
?>

Der Ausgang des obigen Code könnten sein:

The file is ok.


<PHP String Referenz