Jump to: navigation, search

Php md5 file

From w3cyberlearnings

Contents

PHP function md5_file

This function calculates the MD5 hash of a file. The result of the md5_file() function is the MD5 Message-Digest and this message intended for digital signature application.

Syntax md5_file

  • file: file name to be calculated
  • raw: True (Raw 16 character binary format), False (Default: 32 characters hex number)
md5_file(file,raw)

Example 1

  • Generate an md5-digest for a file.
<?php

$filename ="test1.txt";
$md5file = md5_file($filename);
echo $md5file;
?>

Output

e9d7777a6b1f68baa097cae474512d05

Example 2

  • Check whether the file md5-digest message is matched its original file.
<?php

$filename = "test1.txt";
$md5_test1 = 'e9d7777a6b1f68baa097cae474512d05';
$md5file = md5_file($filename);
if ($md5_test1 == $md5_test1) {
	echo 'This digest-message is correct, and the file is fine!';
} else {
	echo 'This file has been modified from its original';
}
?>

Output

This digest-message is correct, and the file is fine!

Example 3

<?php

$filename ="test1.txt";
$md51 = md5_file($filename,TRUE);
$md52 = md5_file($filename,FALSE);

echo $md51 . '<br/>';
echo $md52 . '<br/>';
?>
 

Output

é×wzk�hº —ÊätQ-�
e9d7777a6b1f68baa097cae474512d05

Related Functions


Navigation
Web
SQL
MISC
References