note 33963 added to function.md5-file

From: Date: Sat, 12 Jul 2003 04:56:42 +0000
Subject: note 33963 added to function.md5-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-51952@lists.php.net to get a copy of this message
Heres a md5_checksum function I made, it works on local and remote files. You can specify which mode to use, local or remote mode. Also if you use remote file checking, you can specify an estimated file size. If your checking a local file, it will use md5_file if it exists, if not, use fopen and get the md5 hash checksum of the file. I also want to note, the remote file checksum wont be the same as if you did it locally unless you give the files exact file size as the estimated size. If you dont knoow the exact size, just leave the estimated size its default 1024 bytes for compatibility with future remote checksums. function md5_checksum($file,$remote=false,$estimated_size=0) { if (file_exists($file) or $remote==true) { if (function_exists('md5_file') and $remote!=true) { $checksum = @md5_file($file); } else if ($fd = @fopen($file, 'rb')) { if ($remote!=true) { $filesize = @filesize($file); } else { $estimated_size = intval($estimated_size); if($estimated_size>0) { $filesize = $estimated_size; } else { $filesize = 1024; } } $contents = @fread($fd, $filesize); @fclose ($fd); $checksum = md5($contents); } else return false; return trim($checksum); } return false; } ---- Manual Page -- http://www.php.net/manual/en/function.md5-file.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33963 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33963&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33963&report=yes

« previous php.notes (#51952) next »