【发布时间】:2012-10-06 14:57:47
【问题描述】:
我有一个来自 facebook 的图片网址:
https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-prn1/s720x720/156510_443901075651849_1975839315_n.jpg
我需要将其保存在本地。当我使用file_get_contents 时,它给出了错误failed to open stream。当我在浏览器中打开图像时,它显示正常。我只是明白该怎么做。
事实上,我以以下方式使用 curl 并没有得到任何响应
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
curl_close($ch);
$filename = 'ex'.$src['photo_id'].'.jpg';
$imgRes = imagecreatefromstring($response);
imagejpeg($imgRes, $filename, 70);
header("Content-Type: image/jpg");
imagejpeg($imgRes, NULL, 70);
【问题讨论】:
-
您的设置可能不允许 url_fopen。您可能需要改用 curl。
-
+1 ^ CURL 是一个更好的选择。
-
我可以知道如何使用 curl 提取图像
-
使用 curl 但没有得到任何响应
-
这与 SSL 有关。改用 http:// 试试。或者在使用 CURL 时使用签名证书。
标签: php facebook facebook-graph-api curl file-get-contents