note 63571 deleted from function.md5-file by bjori

From: Date: Fri, 24 Mar 2006 08:58:02 +0000
Subject: note 63571 deleted from function.md5-file by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106519@lists.php.net to get a copy of this message
Note Submitter: adam dot chou at gmail dot com Reason: bad code ---- 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]);

« previous php.notes (#106519) next »