You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求可生成跳过病毒扫描的公开共享谷歌云盘文件直链的PHP脚本

PHP脚本:生成谷歌云盘公开文件直接下载链接(跳过病毒扫描)

我经常碰到开发者需要绕开谷歌云盘病毒扫描警告直接下载文件的需求,刚好可以给你写一个纯PHP实现的脚本——完全不需要调用谷歌官方API,靠模拟浏览器请求就能处理确认逻辑,和你提到的那些站点原理一致。

原理说明

公开共享的谷歌云盘文件,当谷歌判定文件存在潜在风险时,会强制跳转到病毒扫描页面。我们可以通过以下两步生成直接下载链接:

  1. 请求谷歌云盘的导出接口,自动检测是否需要确认码(部分文件会要求这一步)
  2. 把确认参数(如果有)拼接到最终下载链接里,就能直接触发下载,跳过扫描页面

完整PHP脚本

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['file_id'])) {
    $fileId = trim($_POST['file_id']);
    if (empty($fileId)) {
        echo "请输入有效的谷歌云盘文件ID";
        exit;
    }

    // 第一步:请求导出链接,获取可能需要的确认码
    $exportUrl = "https://drive.google.com/uc?export=download&id={$fileId}";
    $ch = curl_init($exportUrl);
    
    // 模拟浏览器请求头,避免被谷歌拦截
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36');
    
    $response = curl_exec($ch);
    $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $headers = substr($response, 0, $headerSize);
    $body = substr($response, $headerSize);
    curl_close($ch);

    // 提取确认码(如果页面中存在)
    $confirmCode = '';
    if (strpos($body, 'confirm=') !== false) {
        preg_match('/confirm=([a-zA-Z0-9_-]+)/', $body, $matches);
        $confirmCode = $matches[1] ?? '';
    }

    // 构造最终的直接下载链接
    $directDownloadUrl = "https://drive.google.com/uc?export=download&id={$fileId}";
    if (!empty($confirmCode)) {
        $directDownloadUrl .= "&confirm={$confirmCode}";
    }

    // 输出结果
    echo "<h3>生成的直接下载链接:</h3>";
    echo "<a href='{$directDownloadUrl}' target='_blank'>{$directDownloadUrl}</a>";
} else {
    // 显示文件ID输入表单
?>
    <style>
        .form-container { max-width: 500px; margin: 2rem auto; padding: 1rem; border: 1px solid #eee; border-radius: 8px; }
        input { width: 100%; padding: 0.8rem; margin: 0.5rem 0; box-sizing: border-box; }
        button { padding: 0.8rem 1.5rem; background: #1a73e8; color: white; border: none; border-radius: 4px; cursor: pointer; }
    </style>
    <div class="form-container">
        <h2>谷歌云盘直接下载链接生成器</h2>
        <form method="POST">
            <label for="file_id">输入公开文件ID:</label>
            <input type="text" id="file_id" name="file_id" placeholder="例如:1C25uoL6nIqqNhex3wm8VwODsO2q2pXBt" required>
            <button type="submit">生成直接下载链接</button>
        </form>
    </div>
<?php
}
?>

使用说明

  1. 将脚本上传到支持PHP和cURL扩展的服务器上
  2. 访问脚本页面,输入公开共享文件的ID(就是云盘共享链接中id=后面的字符串)
  3. 点击生成按钮,即可得到无需经过病毒扫描的直接下载链接

注意事项

  • 仅对公开共享的文件有效,私有文件或需要权限的文件无法生成链接
  • 超大文件可能仍会触发谷歌的额外验证,但绝大多数普通文件都能正常跳过扫描
  • 确保服务器开启了cURL扩展,否则脚本无法正常运行

内容的提问来源于stack exchange,提问作者Umang Pokharna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:34:07