Log in

View Full Version : Beginner here, little help



cat250
01-13-2012, 07:27 AM
Hi there! First of all, sorry for my bad english, isn't native language. :(

I have:

if*(file_exists($image['Poster']))*{
**echo*"a".$image['Poster']."";
}*else*{
**echo*"b".$json['Poster']."";*}*

And the script return:


bhttp://ia.media-imdb.com/images/M/MV5BMTYwNTE3NDYzOV5BMl5BanBnXkFtZTcwNTU5MzY0MQ@@._V1_SX320.jpg
bN/A

1 Poster image: http://ia.media-imdb.com/images/M/MV5BMTYwNTE3NDYzOV5BMl5BanBnXkFtZTcwNTU5MzY0MQ@@._V1_SX320.jpg
2 Poster image: not exist - return N/A

So it seems the script isn't work. Can someone fix this for me? Thanks. :)

traq
01-14-2012, 02:46 AM
if*(file_exists($image['Poster']))*{
**echo*"a".$image['Poster']."";
}*else*{
**echo*"b".$json['Poster']."";*}*
You should actually be getting a parse error. Are the asterisks ( * ) actually in your PHP script?

Assuming you have this script:
if(file_exists( $image['Poster'] )){
echo "a".$image['Poster']."";
}else{
echo "b".$json['Poster']."";
}then your script does appear to be working, even though it's not the result you expected/want.

1. file_exists() can work with URLs in some cases, but most servers do not enable/allow this by default. That's probably why your if() statement is failing.

filesystem functions are intended for, and are much more reliable with, file paths on your own server.

2. IMDB blocks direct requests on its media server - likely an attempt to reduce hotlinking:
Referral Denied

You don't have permission to access "http://ia.media-imdb.com/images/M/MV5BMTYwNTE3NDYzOV5BMl5BanBnXkFtZTcwNTU5MzY0MQ@@._V1_SX320.jpg" on this server.
so, your attempt to check if the image exists probably wouldn't be successful anyway. Which brings us to...

3. What are you trying to accomplish with echo "a".$image['Poster']? Are you trying to display the image? As you see with your own code, this will only print the contents of $image['Poster'] (i.e., the URL).

If you want to display an image (one that you aren't denied access to), you need to print an <img> tag with the appropriate source URL.

Alternatively, you could read the image file (one on your own server, or one you have access to) and print the file's contents, along with the appropriate content-type headers. But that's more complicated, usually unnecessary, and probably not what you're trying to do.

----------------------------------------

In any case, can you explain more about what you're trying to accomplish? What do you want the end result to be?