【问题标题】:Send image from google drive or get image name by google drive url从谷歌驱动器发送图像或通过谷歌驱动器 url 获取图像名称
【发布时间】:2020-03-15 17:20:55
【问题描述】:

我有谷歌驱动器网址,例如:https://drive.google.com/file/d/1u-FuKcHPigtDdaW4a1It4ZRUtgl0RqQW/view 我想做的就是用 PHP CURL 下载它,这是不可能的。它只是给了我带有 html 内容的图像文件,谷歌说他们不能让这个过程。那么有什么方法可以下载这张图片吗?或者也许有办法通过这个网址获取文件名?谢谢。

内部图片,当我用记事本打开它时,我看到:

<HTML>
<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Temporarily</H1>
The document has moved <A HREF="https://doc-0g-bg-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/q49qhj97jrb5sim417hnaufqbno3fusq/1584296100000/13001434112142294195/*/1u-FuKcHPigtDdaW4a1It4ZRUtgl0RqQW?e=download">here</A>.
</BODY>
</HTML>

卷曲:

<?php

function grab_image($url,$saveto){
    $ch = curl_init ($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    $raw=curl_exec($ch);
    curl_close ($ch);
    if(file_exists($saveto)){
        unlink($saveto);
    }
    $fp = fopen($saveto,'x');
    fwrite($fp, $raw);
    fclose($fp);
}


grab_image('https://drive.google.com/a/file/uc?id=1u-FuKcHPigtDdaW4a1It4ZRUtgl0RqQW&export=download', 'test.jpg');

 ?>

【问题讨论】:

    标签: php curl callback drive


    【解决方案1】:

    https://curl.haxx.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html

    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      • 2018-01-23
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 2021-12-15
      相关资源
      最近更新 更多