2013-07-15 43 views
0

在HTML呈现你好,我有一个PHP文件与包括:但是PHP图像不使用img元素

的图片显示正常,当我访问了PHP文件,当我尝试以显示它在HTML模板,它显示了在一条门缝的小IMG,所以基本上说:“没有找到图片”

<img src="http://konvictgaming.com/status.php?channel=blindsniper47"> 

是我使用的HTML模板来显示它是什么,但它只是似乎并不想显示,我试过寻找旁边没有结果为我的具体问题,虽然我确定我可能搜索了错误的标题

添加代码从OP下面

$clientId = '';    // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications 
$online = 'online.png';  // Set online image here 
$offline = 'offline.png'; // Set offline image here 
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true); 

if ($json_array['stream'] != NULL) { 
    $channelTitle = $json_array['stream']['channel']['display_name']; 
    $streamTitle = $json_array['stream']['channel']['status']; 
    $currentGame = $json_array['stream']['channel']['game']; 

    echo "<img src='$online' />"; 
} else { 
    echo "<img src='$offline' />"; 
} 
+0

您不是指图像。实际图片网址是http://konvictgaming.com/offline.png – raam86

+0

您指的是'http:// konvictgaming.com/offline.png'图片 – swapnesh

回答

1

在status.php文件,在那里你输出<img src=...变化的标记它读取如下

$image = file_get_contents("offline.png"); 
header("Content-Type: image/png"); 
echo $image; 

这将为请求发送实际图像,而不是发送标记。对于img标记,标记无效src

更新您的代码修改如下。

$clientId = '';    // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications 
$online = 'online.png';  // Set online image here 
$offline = 'offline.png'; // Set offline image here 
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true); 

header("Content-Type: image/png"); 
$image = null; 
if ($json_array['stream'] != NULL) { 
    $channelTitle = $json_array['stream']['channel']['display_name']; 
    $streamTitle = $json_array['stream']['channel']['status']; 
    $currentGame = $json_array['stream']['channel']['game']; 

    $image = file_get_contents($online); 
} else { 
    $image = file_get_contents($offline);   
} 
echo $image; 
+0

我很抱歉,但是当我提到php时,我非常吝啬,你能给我一个完整的例子吗?作为即时通讯不确定到它应该去/删除/修改的xD 我基本上只是想让它显示为在线/离线图像,目前游戏/标题心不是需要 所以理论上我只是想

+0

我需要看到你的代码更多你的回声你当前的标记 – DevZer0

+0

http://pastebin.com/Mn7gM7D4 但由于某种原因,现在我得到 解析错误:语法错误,意外的T_VARIABLE在/ home/isykonvi/public_html /流/第3行的status.php –

2

指定在HTTP报头,这是一个PNG(或任何)图像!

(默认情况下它们将被解释为text/html)

+0

对不起,Stack似乎删除了链接到它的PHP文件正在回应我的图片 http://pastebin.com/cbtKkWS1 正如您可以看到它回声的图像&正确地返回它,当X人上线/离线他们的流上的图像相应地改变,我以前img scrd一个像这样的PHP文件,我似乎无法弄清楚在这种情况下它有什么问题! –

+0

将'header('Content-Type:image/png');'添加到链接文件的第一行。 –

6

URL是不是一个图像,它是具有以下内容

<img src='offline.png' alt='Offline' /> 

网页不能被显示为图像的网页。您需要编辑页面才能传送实际图像,并带有正确的http标题。

您可以通过搜索“php动态图像”找到一些帮助。

+0

真实图片位于:http://konvictgaming.com/offline.png – 2013-07-15 11:45:58

+0

对不起,它似乎堆栈删除链接到它的PHP文件,这是回应我的图像 http:// pastebin。com/cbtKkWS1 正如你可以看到它回声的形象和正确地返回它,当X人去他们的流在线/离线图像相应地改变,我以前img scrd这样的PHP文件,我不能似乎弄清楚在这种情况下它有什么问题! –

+0

好的,它正确地回应了html。因此,当您将其作为网页打开时,它看起来很好。但是如果你想在''中使用它,你需要该页面作为图像而不是html页面。 – Joost

1

我想你改变图片dynmaclly在这个页面上。

最简单的方法以最少的变化只是将被使用iframe:

<iframe src="http://konvictgaming.com/status.php?channel=blindsniper47"> </iframe>