Gehe zu deutscher Webseite

ViaThinkSoft CodeLib

This article is in:
CodeLibProgramming aidsPHP

function create_sfv($sfv_file, $files) {
        $out = chr(0xEF).chr(0xBB).chr(0xBF); // UTF-8 BOM
        $out .= "; Generated by ViaThinkSoft\r\n";
        foreach ($files as $file) {
                $crc32 = strtoupper(crc32_file($file));
                $out .= "$file $crc32\r\n";
        }
        file_put_contents($sfv_file, $out);
}

function swapEndianness($hex) {
        return implode('', array_reverse(str_split($hex, 2)));
}

function crc32_file($filename, $rawOutput = false) {
        $out = bin2hex(hash_file ('crc32b', $filename , true));
        if (hash('crc32b', 'TEST') == 'b893eaee') {
                // hash_file() in PHP 5.2 has the wrong Endianess!
                // https://bugs.php.net/bug.php?id=47467
                $out = swapEndianness($out);
        }
        return $out;
}
Daniel Marschall
ViaThinkSoft Co-Founder

Feedback? Problems? Please drop us a message!

Your name (optional):

E-mail address (optional):

Message: