note 33963 deleted from function.md5-file by nlopess

From: Date: Sun, 12 Sep 2004 17:52:04 +0000
Subject: note 33963 deleted from function.md5-file by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76545@lists.php.net to get a copy of this message
Note Submitter: slynderdale ---- 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; }

« previous php.notes (#76545) next »