在下载文件之前,有没有办法获取远程文件https://drive.google.com/uc?export=download&id=54fs54dg45f1f112f2的大小?
答案 0 :(得分:1)
你可以发出一个卷曲请求来获取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
)