im trying this: load http://example.com/nickname/picture (nickname loaded var in url visit, that´s working) decode json site this
{ "picture": "https://example.com/hf8329yrh8oq.jpg" } load picture tried:
function curlget($url) { $crl = curl_init(); $timeout = 5; curl_setopt ($crl, curlopt_url,$url); curl_setopt ($crl, curlopt_returntransfer, 1); curl_setopt ($crl, curlopt_connecttimeout, $timeout); $status = curl_exec($crl); curl_close($crl); return $status; } $profpiccurl = curlget('https://example.com/'.urlencode($_get['nickname']).'/picture') $profpic = json_decode($profpiccurl,true); echo file_get_contents($profpic.["picture"]); i know didn´t handle errors , stuff in script, want work real image first before.
so mean question: how display , image decoded json site?
do need curl?
can replace file_get_contents curlget in code
<?php $profpic = json_decode( file_get_contents( 'https://example.com/'.urlencode( $_get['nickname'] ).'/picture' ) ); if ( $profpic ) { // valid json object if ( isset( $profpic->picture ) ) { // profile picture exists $profpic = $profpic->picture; $extension = strtolower( pathinfo( $profpic, pathinfo_extension ) ); // image extension $content = file_get_contents( $profpic ); // content of image if ( $content ) { header( "content-type: image/".$extension ); // set mime type echo $content; // output content exit(); } } } echo "file not found"; // there errors :\ ?>
Comments
Post a Comment