php - 将文件从 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
但它仍然无法正常工作。你认为谷歌试图避免服务器到服务器的复制吗?还是有另一种方法可以做到这一点?
解决方案
如果您想使用自己的应用程序获取文件,您应该使用 API(应用程序编程接口)来获取这些文件。
查看 Google Drive 的文件下载文档
PHP 中的示例下载片段:
$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
$response = $driveService->files->get($fileId, array(
'alt' => 'media'));
$content = $response->getBody()->getContents();
推荐阅读
- joomla - Joomla 4:在布尔值上调用成员函数 setState()
- c++ - 使用显式命名空间限定符时模板实例化行为发生变化?
- android-studio - 如何在 Android Studio 上运行 zip 文件
- angular - Angular 4:文件上传:无法在“HTMLInputElement”上设置“value”属性
- docker - 无法在 Ubuntu 上安装/运行 docker-ce
- reactjs - 反应 SetState 不立即更新状态
- mips - 流水线处理器中的缓存实现
- javascript - 使用对象 javascript 添加或附加对象
- php - 获取更新时间 ACF 字段
- javascript - 如何在 VS Code 中的“script.js”文件中调试\编译\查找我的 JavaScript 代码中的错误?