从PHP中的Google云端硬盘链接获取图像


Getting image from Google Drive link in PHP

我想从php中的谷歌驱动器URL中提取图像,为此首先我需要获取html部分,然后获取img src,然后获取实际图像。但不知何故,我无法获得 html 部分.我已经尝试了file_get_contents卷曲请求。

网址 - https://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1

这是我的卷曲脚本

<?php
$url = "http://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1";
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); 
curl_close($ch);      
print_r($output);

输出

<HTML>
<HEAD>
<TITLE>Moved Permanently</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Permanently</H1>
The document has moved <A HREF="https://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1">here</A>.
</BODY>
</HTML>

这是我使用 file_get_contents 的 php 脚本

<?php
$url = "http://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1";
$html= file_get_contents($url);
print_r($html);

输出

Warning: file_get_contents(http://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1): failed to open stream: No such file or directory on line 5

allow_url_fopen在PHP中是正确的.ini

任何帮助不胜感激。

您的 http 请求被重定向到 https。使用 https,不会有重定向。

而不是 curl 使用 simplehtmldom 从谷歌驱动器中抓取数据

这是好文章

参考链接 1 和链接 2