2014-05-22 135 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