【发布时间】:2018-02-10 16:16:13
【问题描述】:
有没有办法在下载文件之前获取远程文件https://drive.google.com/uc?export=download&id=54fs54dg45f1f112f2 的大小?
【问题讨论】:
标签: php google-drive-api drive
有没有办法在下载文件之前获取远程文件https://drive.google.com/uc?export=download&id=54fs54dg45f1f112f2 的大小?
【问题讨论】:
标签: php google-drive-api drive
您可以发出 curl 请求以获取 sizeBytes。
<?php
$id = '0ByzJffaEk18uN2ZLeGlIRGVOaDJmWS1WU1RUN3d***';
$ch = curl_init('https://drive.google.com/uc?id='.$id.'&export=download');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, []);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
$object = json_decode(str_replace(')]}\'', '', $result));
print_r($object);
结果:
stdClass Object
(
[disposition] => SCAN_CLEAN
[downloadUrl] => https://doc-08-8o-docs.googleusercontent.com/docs/...
[fileName] => filename.sh
[scanResult] => OK
[sizeBytes] => 4936
)
【讨论】: