foreach ($files as $fdata) {
    echo $fdata['relpath'] . "\n";
    // Don't take checksums of directories
    if ($fdata['directory']) {
        continue;
    }
    $fname = $fdata['name'];
    $prel = $fdata['relpath'];
    $path = $basedir . $prel;
    if ($fname[0] == '.' || !is_readable($path)) {
        // serendipity_traversePath already excludes CVS and svn directories
        continue;
    }
    // Are we SURE we should checksum this file?
    if (is_file($path) && !in_array($fname, $excludes)) {
        $sum = serendipity_FTPChecksum($path);
        // If you find the valid file with an MD5 sum of 0, let me know. ;)
        if ($sum) {
            $sums[$prel] = $sum;
        }
        continue;
    }
}
if (!empty($sums)) {
    $file = fopen($basedir . '/' . 'checksums.inc.php', 'w');
    if (!$file) {
        die('Unable to open output file!');
    }
    fwrite($file, '<?php' . "\n" . 'global $serendipity;' . "\n" . '$serendipity[\'checksums_' . $vmatch[1] . '\'] = array (' . "\n");
    foreach ($sums as $fname => $sum) {
        fwrite($file, "'{$fname}' => '{$sum}',\n");
/**
 * Validate checksums for all required files.
 * 
 * @return A list of all files that failed checksum, where keys are the 
 *    relative path of the file, and values are the bad checksum
 */
function serendipity_verifyFTPChecksums()
{
    global $serendipity;
    $badsums = array();
    // Load the checksums
    $f = S9Y_INCLUDE_PATH . 'checksums.inc.php';
    if (!file_exists($f) || filesize($f) < 1) {
        return $badsums;
    }
    require_once $f;
    // Verify that every file in the checksum list was uploaded correctly
    $basedir = realpath(dirname(__FILE__) . '/../');
    if (!is_array($serendipity['checksums_' . $serendipity['version']])) {
        return $badsums;
    }
    foreach ($serendipity['checksums_' . $serendipity['version']] as $prel => $sum) {
        $path = $basedir . '/' . $prel;
        // Don't take checksums of directories
        if (is_dir($path)) {
            // Weird that it's even here.
            continue;
        }
        // Can't checksum unreadable or nonexistent files
        if (!is_readable($path)) {
            $badsums[$prel] = 'missing';
            continue;
        }
        // Validate checksum
        $calcsum = serendipity_FTPChecksum($path);
        if ($sum != $calcsum) {
            $badsums[$prel] = $calcsum;
            continue;
        }
    }
    return $badsums;
}
 /**
  * checks updates checksum file array with updates realfiles
  * @param   string version
  * @return  error
  */
 function showChecksumErrors($version)
 {
     global $serendipity;
     $updateDir = (string) $serendipity['serendipityPath'] . 'templates_c/' . "serendipity-{$version}/";
     $checksumFile = (string) $updateDir . "serendipity/checksums.inc.php";
     include_once $checksumFile;
     $checksums = $serendipity['checksums_' . $version];
     $errors = array();
     foreach ($checksums as $file => $checksum) {
         $check = serendipity_FTPChecksum($updateDir . "serendipity/" . $file);
         if ($checksum != $check) {
             $errors[] = $updateDir . "serendipity/" . $file;
         }
     }
     ob_start();
     echo '<p class="msg_error"><span class="icon-error"></span>Updating failed, because the integrity-test for the following files failed:</p>';
     echo "<ul>";
     foreach ($errors as $file) {
         echo "<li>{$file}</li>";
     }
     echo "</ul>";
     $integrity_error = ob_get_contents();
     ob_end_clean();
     $this->show_message($integrity_error);
 }