PHP生成Ed2k(电驴)连接

function genEd2k($filepath) {

    $chunk_size = 9728000;

    $ed2khash = '';

    if (!is_file($filepath)) {
            trigger_error('file not found',E_USER_WARNING);
            return False;
        }
    $filesize = filesize($filepath);
    $filename = pathinfo($filepath, PATHINFO_BASENAME);

    if ($filesize <= $chunk_size) {
        $ed2khash = hash_file('md4', $filepath, true);
    } else {
        $_hash_str = '';
        $fp = fopen($filepath,'r');
        while (!feof($fp)) {
            $data = fread($fp, $chunk_size);
            $_hash_str .= hash('md4', $data, True);
        }
        fclose($fp);
        $ed2khash = hash('md4', $_hash_str);
    }

    return sprintf('ed2k://|file|%s|%s|%s', urlencode($filename), $filesize, strtoupper($ed2khash));
}

调用:

echo genEd2k(__DIR__.'/test.rar');
// 输出
// ed2k://|file|test.rar|4150800|4EB96EFD6600264ACB4FAE237C3F7895
去打赏

您的支持将鼓励我们继续创作!

[微信] 扫描二维码打赏

发表评论

电子邮件地址不会被公开。