国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php file_get_contents 無法顯示圖片
迷茫
迷茫 2017-04-10 15:03:57
0
1
416
<?php
$url = "http://nsv.ckcdn.com/images/logo1.png";
$refer = "http://nsv.ckcdn.com/";
$opt=array("http"=>array("header"=>"Referer: " . $refer)); 
$context=stream_context_create($opt); 
$file_contents = file_get_contents($url,false, $context);
echo $file_contents;
?>

我想偽造Referer,然後用 file_get_contents 取得圖片顯示出來,不過顯示出來的是亂碼,該如何解決?

迷茫
迷茫

業(yè)精于勤,荒于嬉;行成于思,毀于隨。

reply all(1)
劉奇
<?php
header("Content-type: image/png");
$url = 'http://misc.360buyimg.com/lib/img/e/logo-201305.png';
$file_contents = file_get_contents($url);
echo $file_contents;
?>

結果可以正常輸出 某東 的LOGO(因為題主提供的圖片鏈接訪問不到,所以找了同為PNG格式的LOGO)。

我覺得問題出在file_get_contents上。文檔:http://cn2.php.net/file_get_contents
因為file_get_contents的作用是整個文件讀入一個字符串中,輸出是當然是以字符串輸出,瀏覽器不知道它是圖片,所以要在加上header("Content-type: image/png"),以告訴瀏覽器這是png格式的圖片,瀏覽器才會顯示成圖片。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template