Reputation: 1322
I am using a PHP script to read some folders in directory and based on their names retrieve their posters. All of this works fine on localhost
. However, when opening externally, this does not work and results in blank
images.
A screenshot from localhost:
89.241.171.100/Prac/
.
PHP generating img tag
:
while (false !== ($entry = readdir($handle))) {
$counter++;
echo "<span class='title'>
<img src='holder.js/200x280/text:$entry'
alt='$entry'
onload='loader(this, \"$entry\")' />
</span>";
if($counter == 5) break;
}
PHP fetching the src for the images called via ajax from loader()
:
if($_POST['title']) {
$title = $_POST['title'];
$imdb = new Imdb();
$movieArray = $imdb->getMovieInfo("$title");
$link = $movieArray["poster_large"];
echo $link;
}
Loader()
function:
$.ajax({
type: 'post',
url: 'loader.php',
data: 'title='+title,
success: function(data) {
img.src = data;
}
});
Upvotes: 0
Views: 868
Reputation: 2617
This looks like an issue with the way you're loading it. These images are being provided via Akamai's CDN and it's not liking the referrer that it's getting.
Here's what's being returned instead of the image payload.
<HTML><HEAD>
<TITLE>Referral Denied</TITLE>
</HEAD><BODY>
<H1>Referral Denied</H1>
You don't have permission to access "http://ia.media-imdb.com/images/M/MV5BMTM5NjM0ODY1NF5BMl5BanBnXkFtZTcwMjk5NjI0Ng@@._V1._SY500.jpg" on this server.<P>
Reference #24.24c633b8.1366714063.2a353f15
</BODY></HTML>
I'm not encouraging breaching anyone's terms but this might be of some use to you, I suspect that passing an empty referrer will fix the problem as when you visit the image URL directly it works (and doesn't send a referrer).
EDIT:
This fiddle is a working example of what I was suggesting earlier. You'll notice the image directly linked is dead, but the one with no referrer loads perfectly.
Upvotes: 1
Reputation: 15605
U could use the Imdb API
Just request the data with : http://imdbapi.org/?id={id}&type=json&plot=simple&episode=1&lang=en-US&aka=simple&release=simple
{id} being the imdb id of the movie. Then u can access the picture with :
$data = json_decode(file_get_contents("http://imdbapi.org/?id={id}&type=json&plot=simple&episode=1&lang=en-US&aka=simple&release=simple"));
$img = $data->poster;
Upvotes: 1