【问题标题】:images are not displayed or they are shown only locally图像不显示或仅在本地显示
【发布时间】:2014-12-22 11:09:42
【问题描述】:

我想显示一些图像,它们的 URL 保存在数据库中,但图像没有显示,当我右键单击图像并选择“查看图像”时,我看到了以下消息:

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

这是我的代码:

<?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>

另外,我在 php 错误日志中看到了这个警告:

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

而 imdbImage.php 是:

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

当我尝试使用以下代码时,它仅在本地显示图像。 &lt;td&gt;&lt;img class='imdbImage' id="image" src=&lt;?php echo $row['posterLink']; ?&gt;' alt="" /&gt;&lt;/td&gt;

谁能告诉我我的代码有什么问题以及为什么没有显示图像?

谢谢

【问题讨论】:

    标签: php html image


    【解决方案1】:

    天哪!只去掉一个空行就解决了问题!!!

    我在第二行的 imdbImage.php 文件中写了&lt;?php.. 所以第一行是空的。 我在this post 找到了解决方案(感谢 Johan)

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

    希望它对其他人也有用:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 2021-06-07
      • 2020-02-09
      • 1970-01-01
      相关资源
      最近更新 更多