【问题标题】:Get size of remote file from google drive URL从谷歌驱动器 URL 获取远程文件的大小
【发布时间】:2018-02-10 16:16:13
【问题描述】:

有没有办法在下载文件之前获取远程文件https://drive.google.com/uc?export=download&id=54fs54dg45f1f112f2 的大小?

【问题讨论】:

    标签: php google-drive-api drive


    【解决方案1】:

    您可以发出 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
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-03
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多