Results 1 to 2 of 2

Thread: Beginner here, little help

  1. #1
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Beginner here, little help

    Hi there! First of all, sorry for my bad english, isn't native language.

    I have:
    Code:
    if*(file_exists($image['Poster']))*{
    **echo*"a".$image['Poster']."";
    }*else*{
    **echo*"b".$json['Poster']."";*}*
    And the script return:

    Code:
    bhttp://ia.media-imdb.com/images/M/MV5BMTYwNTE3NDYzOV5BMl5BanBnXkFtZTcwNTU5MzY0MQ@@._V1_SX320.jpg
    bN/A
    1 Poster image: http://ia.media-imdb.com/images/M/MV...._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.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by cat250 View Post
    PHP Code:
    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:
    PHP Code:
    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:
    Quote Originally Posted by ia.media-imdb.com/images/M/MV5BMTYwNTE3NDYzOV5BMl5BanBnXkFtZTcwNTU5MzY0MQ@@._V1_SX320.jpg
    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?

  3. The Following User Says Thank You to traq For This Useful Post:

    TwitterRooms (01-14-2012)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •