首页 > 解决方案 > 将文件从 Google Drive Server 直接复制到自己的服务器

问题描述

我正在尝试从 Google 服务器的 Google Drive 链接下载文件到我的网络服务器,以避免 PHP POST 中的最大大小为 100。

<?php
$link = $_POST["linkToUpload"];

$upload = file_put_contents("uploads/test".rand().".txt", fopen($link, 'r'));
header("Location: index.php");
?>

插入一个正常的链接http://example.com/text.txt就可以了。问题来自链接 google drive https://drive.google.com/uc?authuser=0&id=000&export=download。这是来自 Google Drive 的直接链接,但它不起作用。所以我尝试插入我获得的在本地下载文件的链接,https://doc-08-bo-docs.googleusercontent.com/docs/securesc/000/000/000/000/000/000?e=download但它仍然无法正常工作。你认为谷歌试图避免服务器到服务器的复制吗?还是有另一种方法可以做到这一点?

标签: phphtmlgoogle-drive-api

解决方案


如果您想使用自己的应用程序获取文件,您应该使用 API(应用程序编程接口)来获取这些文件。

查看 Google Drive 的文件下载文档

PHP 中的示例下载片段:

$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
$response = $driveService->files->get($fileId, array(
    'alt' => 'media'));
$content = $response->getBody()->getContents();

推荐阅读