Reputation: 3828
I have the following url which returns an image in the body, How would I assign that image to a variable so that I could save it or use it within my code?
The following code returns noting:
<?php
$url = "https://media.licdn.com/dms/image/C4E03AQGOM3p0fHNkwQ/profile-displayphoto-shrink_100_100/0?e=1556755200&v=beta&t=qeQFKYXpev2ZW3hmP1ODDPd3DYPWvl-GaUnPSZG-aQA";
$image = file_get_contents($url);
echo $image;
?>
Upvotes: 0
Views: 86
Reputation: 1815
If you simply want to view an image from a URL, just put that url in the src
attribute of an img
element like this :
echo '<img src="' . $url . '"/>';
otherwise, if you have to view it from the fetched data of that url, then your question have been answered here:
php: recreate and display an image from binary data (specifically @Krab's answer)
Upvotes: 2