skip to Main Content

My PHP version is 5.6.40.
I have a variable, in which I want to store an image url.

$imageurl = "http://i132.photobucket.com/albums/q13/animalhelper2006/1376.jpg";

And I’m using file_get_contents function to get this image.

$contents = file_get_contents($imageurl);

But it does not work, it shows empty result. But when I tried to directly load image url, it worked.

$contents = file_get_contents("http://i132.photobucket.com/albums/q13/animalhelper2006/1376.jpg");

What’s wrong? please help.

Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Follow @CBroe way. I'm used var_dump and see the length is different. After many checking I found the variable is hex code http://i132.photobucket.com/albums/q13/animalhelper2006/1376.jpg Final I used html_entity_decode function and it working fine now.

    $contents = file_get_contents(html_entity_decode($imageurl));
    

  2. Your problem might come from file name which is included space (" ").
    You can try using urlencode file name before parsing it into file_get_contents.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search