PHP: md5_file - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

md5 ltrim

Last updated: Fri, 26 Jan 2007

view this page in

# md5_file

(PHP 4 >= 4.2.0, PHP 5)

md5_file -- Возвращает MD5 хэш файла

## Description

string md5_file ( string filename [, bool raw_output] )

Вычисляет MD5 хэш файла, имя которого задано аргументом `filename` используя алгоритм MD5 RSA Data Security, Inc. и возвращает этот хэш. Хэш представляет собой 32-значное шестнадцатеричное число. Если необязательный аргумент `raw_output` имеет значение `TRUE`, то возвращается бинарная строка из 16 символов.

> Замечание: Необязательный аргумент `raw_output` был добавлен в PHP 5.0.0 и по умолчанию равен `FALSE`

По назначению эта функция аналогична консольной программе md5sum.

См. также описание функций md5(), crc32() и sha1_file().

add a note User Contributed Notes
md5_file
bubba at revbubba dot com
29-Mar-2005 04:56
`a working example of the usage of this function, to confirm a specific file has not been modified (replace all instances of "myfile.xxx" with your filename):
<?php
$chkfilename = "myfile.xxx";
$chkmd5return = md5_file($chkfilename);
if ($chkmd5return != "myfile.xxx's md5 value") {
echo "You have replaced myfile.xxx with an unknown version of the file, please replace the original file.";
} else {
(your code to be executed, now that it has confirmed your myfile.xxx has been unmodified)
}
?>
To find out the file's md5 value, create a new .php doc, and put this code in it:
<?php
$chkfilename = "myfile.xxx";
$chkmd5return = md5_file($chkfilename);
echo $chkmd5return;
?>
Then upload the new .php doc to your webserver and navigate to it. Be sure to delete the new .php doc once you have plugged in the value it spits out, into the "myfile.xxx's md5 value" in the first example above.
I just thought this example might be helpful to someone somewhere... if you php.net people feel it needs editing or deletion, I leave it to your discretion. ;)`
richard at interlink dot com dot au
16-Nov-2004 12:57
`For those of you with PHP 4 that want to output the "raw" 128 bit hash, all you need to do is send it to pack to convert the hex string into the raw output.
ie:
$filename="checkthisfile.bin";
$rawhash=pack("H*",md5_file($filename));`
add a note
md5 ltrim

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST