dsa88886666 2014-12-22 11:09
浏览 11

图像不显示或仅在本地显示

I would like to display some images which their URL is saved in DB, but the images are not diplayed and when I right click on the image and select "view image" I see this message:

http://localhost/imdbImage.php?url=http://ia.media-imdb.com/images/M/MV5BMjExNzM0NDM0N15BMl5BanBnXkFtZTcwMzkxOTUwNw@@._V1_SY317_CR0,0,214,317_AL_.jpg cannot be diplayed because it contains errors

This is my code:

<?php
while ($row = $query->fetch(PDO::FETCH_ASSOC)):
?> 
    <tr>
       <td><img class='imdbImage' id="image" src='imdbImage.php?url=<?php echo $row['posterLink']; ?>' alt="" /></td>
       <td> ....
       ...
    </tr>

Also, I see this warning in php error log:

PHP Warning: file_get_contents(Null): failed to open stream: No such file or directory in /var/www/imdbImage.php on line 6, referer: http://localhost/movielist.php

while imdbImage.php is:

<?php
header("Content-type: image/jpeg");
//URL for IMDb Image.
$url = rawurldecode($_REQUEST['url']);
echo file_get_contents($url);   //THIS IS LINE 6 //
?>

When I try with the following code, it only shows the images locally. <td><img class='imdbImage' id="image" src=<?php echo $row['posterLink']; ?>' alt="" /></td>

Could someone kindly let me know what is the problem with my code and why the images are not shown?

Thanks

  • 写回答

1条回答 默认 最新

  • driuwt9557 2014-12-22 11:28
    关注

    OMG! The problem was solved only by removing one blank line!!!

    I wrote <?php in imdbImage.php file in the second line.. so the first line was empty. I found the solution in this post (Thanks to Johan)

    You must not output anything before header(). Just start your document with <?php followed by the code for displaying the image. Skip the html tags. Do not even write a single blankline before header().

    Hope it would be useful for someone else too :)

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序