note 63571 added to function.md5-file
| From: | adamdotchouatgmaildotcom at osu1 dot php dot net | Date: | Fri, 24 Mar 2006 02:26:25 +0000 |
| Subject: | note 63571 added to function.md5-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106509@lists.php.net to get a copy of this message | ||
i had a need to create something that would md5 an entire directory to ensure that a directory being
copied to another location would match the original... it just saves the md5 of the directory to a
file but i'm sure all you smart people out there can figure out how to hack this for your own
purposes
function parse_dir($fp, $path)
{
$d1 = dir($path);
$files = array();
while (false !== ($files[] = $d1->read()));
// removes the false, ., .., then reindex
unset($files[count($files) - 1]);
unset($files[0]);
unset($files[1]);
sort($files);
for($i = 0; $i < count($files); $i++) {
$md5sum = md5($files[$i])."\n";
fwrite($fp, $md5sum);
if (is_dir("$path/$files[$i]"))
parse_dir($fp, "$path/$files[$i]");
}
}
function md5dir($filename)
{
$tempname = tempnam("/tmp", "md5list");
$fp = fopen($tempname, "w+");
parse_dir($fp, getcwd());
fclose($fp);
$fp = fopen($filename, "w+");
fwrite($fp, md5_file($tempname));
fclose($fp);
unlink($tempname);
}
md5dir($argv[1]);
----
Server IP: 64.71.164.2
Probable Submitter: 207.104.65.139
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.md5-file.php
Edit -- http://master.php.net/note/edit/63571
Del: integrated -- http://master.php.net/note/delete/63571/integrated
Del: useless -- http://master.php.net/note/delete/63571/useless
Del: bad code -- http://master.php.net/note/delete/63571/bad+code
Del: spam -- http://master.php.net/note/delete/63571/spam
Del: non-english -- http://master.php.net/note/delete/63571/non-english
Del: in docs -- http://master.php.net/note/delete/63571/in+docs
Del: other reasons-- http://master.php.net/note/delete/63571
Reject -- http://master.php.net/note/reject/63571
Search -- http://master.php.net/manage/user-notes.php