Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

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().



md5> <ltrim
Last updated: Fri, 26 Jan 2007
 
add a note add a note User Contributed Notes
md5_file
potsed [at] gmail [dot] com
27-May-2007 04:12
Heres a function to give an md5 for an entire directory..

function MD5_DIR($dir)
{
    if (!is_dir($dir))
    {
        return false;
    }
   
    $filemd5s = array();
    $d = dir($dir);

    while (false !== ($entry = $d->read()))
    {
        if ($entry != '.' && $entry != '..')
        {
             if (is_dir($dir.'/'.$entry))
             {
                 $filemd5s[] = MD5_DIR($dir.'/'.$entry);
             }
             else
             {
                 $filemd5s[] = md5_file($dir.'/'.$entry);
             }
         }
    }
    $d->close();
    return md5(implode('', $filemd5s));
}
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));

md5> <ltrim
Last updated: Fri, 26 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571