0

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

mOna
  • 2,341
  • 9
  • 36
  • 60

1 Answers1

0

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 :)

Community
  • 1
  • 1
mOna
  • 2,341
  • 9
  • 36
  • 60