Search code examples
phpfile-get-contents

file_get_contents not working with variable PHP


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


Solution

  • 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));