【发布时间】: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');
?>
【问题讨论】: