Exemple
Calculer le hachage MD5 du fichier texte "test.txt" :
<?php
$filename = "test.txt";
$md5file = md5_file($filename);
echo $md5file;
?>
au-dessus de la sortie du code sera:
d41d8cd98f00b204e9800998ecf8427e
Définition et utilisation
Le md5_file() calcule le hachage MD5 d'un fichier.
Le md5_file() fonction utilise RSA Data Security, Inc. MD5 algorithme Message-Digest.
De la RFC 1321 - L'algorithme MD5 Message-Digest: "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." des "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." d' "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."
Pour calculer le hachage MD5 d'une chaîne, utilisez la md5() fonction.
Syntaxe
md5_file( file,raw )
Paramètre | La description |
---|---|
file | Champs obligatoires. Le fichier à calculer |
raw | Optionnel. Une valeur booléenne qui spécifie le format de sortie hexadécimal ou binaire:
|
Détails techniques
Valeur de retour: | Retourne le hachage MD5 calculé sur la réussite, en cas d'échec |
---|---|
PHP Version: | 4.2.0+ |
changelog: | Le paramètre brut a été ajouté en PHP 5.0 PHP 5.1, il est possible d'utiliser md5_file() avec des enveloppes, par exemple md5_file("http://w3ii.com/..") |
autres exemples
Exemple 1
Conservez le hachage MD5 de "test.txt" dans un fichier:
<?php
$md5file = md5_file("test.txt");
file_put_contents("md5file.txt",$md5file);
?>
Test si "test.txt" a été modifiée (qui est si le hachage MD5 a été modifié):
<?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.";
}
?>
au-dessus de la sortie du code pourrait être:
The file is ok.
<PHP chaîne de référence