我正在尝试在我的VPS上运行此代码
<?php
function curl_get_contents($url, array $opts = array()) {
$defaults = array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'Mozilla Firefox 20.0',
CURLOPT_VERBOSE => true
);
$opts = $opts + $defaults;
$ch = curl_init($url);
curl_setopt_array($ch, $opts);
return curl_exec($ch);
}
header('Content-type: image/jpeg');
echo curl_get_contents('http://sphotos-b.ak.fbcdn.net/hphotos-ak-prn1/58678_10151328142003680_1939974573_n.jpg');
?>
当我运行它时,有一个无限循环,我不明白为什么。该功能适用于每个图像网址,但不适用于Facebook。有什么建议吗?
答案 0 :(得分:0)
以下对我有用:
<?php
function curl_get_contents($url, array $opts = array()) {
$defaults = array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'Mozilla Firefox 20.0'
);
$opts = $opts + $defaults;
$ch = curl_init($url);
curl_setopt_array($ch, $opts);
return curl_exec($ch);
}
header('Content-type: image/jpeg');
echo curl_get_contents('link to facebook image');
?>