2014-05-22 138 views
-2

我试图卷曲http://island-alpaca.selfip.com:10202/SnapShotJPEG?Resolution=640x480Quality=Standard这个位置并每次返回空页面。我的代码是卷曲返回null页

$image = 'http://island-alpaca.selfip.com:10202/SnapShotJPEG?Resolution=640x480&Quality=Standard'; 

    $ch = curl_init(); 

    curl_setopt($ch,CURLOPT_VERBOSE,true); 

    curl_setopt($ch, CURLOPT_URL, $image); 

    $store = curl_exec ($ch); 

    echo $store; 
    curl_close ($ch); 

有人可以告诉我失踪了吗?

+1

为什么你在URL中有空间? –

+0

Sudhir给了你答案,你没有returntransfer +没有改变页面的标题为jpg。 –

回答

0

尝试添加

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 

这样的代码将是: -

$image = 'http://island-alpaca.selfip.com:10202/SnapShotJPEG?Resolution=640x480&Quality=Standard'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_VERBOSE,true); 
curl_setopt($ch, CURLOPT_URL, $image); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
$store = curl_exec ($ch); 
curl_close ($ch); 
header("Content-type: image/jpeg"); 
echo $store; 
+0

对不起兄弟不工作 – shuvro

+0

有任何错误尝试toenable error_reporting(1); –

2

尝试做:

... 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $image); 
// Get binary data 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 

$image = curl_exec($ch); 
curl_close($ch); 

// output to browser 
header("Content-type: image/jpeg"); 
echo $image; 

编辑:尽量urlencode()“荷兰国际集团的网址为:

$image = 'http://island-alpaca.selfip.com:10202/SnapShotJPEG?Resolution='.urlencode('640x480&Quality=Standard'); 
+1

+1这是正确的答案!没有标题和二进制设置,它将显示页面中的所有垃圾数据。到OP为什么地球上你想要图像使用CURL为什么不只是使用''标签并使用URL? –

+0

实际上,对于php 5.1.3而言,并不需要binarytransfer。从[php.net](http://www.php.net/manual/en/function.curl-setopt.php):“从PHP 5.1.3开始,此选项不起作用:原始输出将始终返回当使用CURLOPT_RETURNTRANSFER时“。 –

+0

对不起兄弟不工作 – shuvro