MrLarkins Posted September 17, 2010 Share Posted September 17, 2010 OK, i've used it before, but for some reason it's not working. I have 2 pages PAGE 1 (bfbc2.php) <?php $url = 'http://api.bfbcs.com/api/pc'; $value = $_GET['playername']; $postdata = "players=$value&fields=basic"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); $data = curl_exec($ch); curl_close($ch); $data = json_decode($data,true); $player = $data['players']; $stuff = $player['0']; $rank = $stuff['rank']; echo ('<img src="http://www.oskgaming.com/images/bfbc2ranks/'.$rank.'.jpg" />'); ?> PAGE 2 (test.html) <img src="http://www.oskgaming.com/images/bfbc2.php?playername=Lark.s"> if I type http://www.oskgaming.com/images/bfbc2.php?playername=Lark.s I get the image requested if type http://www.oskgaming.com/test.html I get a broken image. Any ideas? Did I make a mistake somewhere? Quote Link to comment Share on other sites More sharing options...
coupe-r Posted September 17, 2010 Share Posted September 17, 2010 Yes, your img src isn't pointing to the file, its pointing to a URL. You need to have it point directly to a .jpg/.gif/.png file. Quote Link to comment Share on other sites More sharing options...
MrLarkins Posted September 17, 2010 Author Share Posted September 17, 2010 How? the <IMG> points to the PHP. the PHP accesses a database, pulls a value and displays jpg named by that pulled value. How can I point the <IMG> at the jpg when I don't know which jpg to use? There are 50 jpg's to choose from! Quote Link to comment Share on other sites More sharing options...
MrLarkins Posted September 17, 2010 Author Share Posted September 17, 2010 Yes, your img src isn't pointing to the file, its pointing to a URL. You need to have it point directly to a .jpg/.gif/.png file. but it IS point to the php file, and the php file outputs the img...so why is a broken image being displayed? i must add that the PHP file runs flawlessly on its own...but when i try <img src=.php>, it shows a broken image Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 17, 2010 Share Posted September 17, 2010 Load the script and 'View Source" to see what you're getting as the src= attribute of the <img> tag. I'll bet the referenced script isn't returning the value you think it is. Quote Link to comment Share on other sites More sharing options...
MrLarkins Posted September 17, 2010 Author Share Posted September 17, 2010 Load the script and 'View Source" to see what you're getting as the src= attribute of the <img> tag. I'll bet the referenced script isn't returning the value you think it is. yep, i've done that. it shows the php file link. Quote Link to comment Share on other sites More sharing options...
schilly Posted September 17, 2010 Share Posted September 17, 2010 That won't work. If you point the src attribute to a php script you must output the image source, not the pathname. Your browser went to that script to load an image and all it got was a string url of an image, not the actual image data. Quote Link to comment Share on other sites More sharing options...
MrLarkins Posted September 17, 2010 Author Share Posted September 17, 2010 That won't work. If you point the src attribute to a php script you must output the image source, not the pathname. Your browser went to that script to load an image and all it got was a string url of an image, not the actual image data. ok, your making more sense...so I need to change my php script instead of having echo ('<img src="http://www.oskgaming.com/images/bfbc2ranks/'.rank.'.jpg" />'); what should it be? do i need to load all 50 image choices into an array? do I need the header(Content: image/jpeg); in my script? Quote Link to comment Share on other sites More sharing options...
schilly Posted September 17, 2010 Share Posted September 17, 2010 You can try instead of echoing the URL. Depending on your server, imagecreatefromjpeg may not allow you to get an image resource from a url. //get image path like in above script header('Content-Type: image/jpeg'); $im = imagecreatefromjpeg($img_url); imagejpeg($im); imagedestroy($im); Quote Link to comment Share on other sites More sharing options...
MrLarkins Posted September 17, 2010 Author Share Posted September 17, 2010 that did it...great catch...here's my final code <?php $url = 'http://api.bfbcs.com/api/pc'; $value = $_GET['playername']; $postdata = "players=$value&fields=basic"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); $data = curl_exec($ch); curl_close($ch); $data = json_decode($data,true); $player = $data['players']; $stuff = $player['0']; $rank = $stuff['rank']; $img_url = 'http://www.oskgaming.com/images/bfbc2ranks/'.$rank.'.jpg'; header('Content-Type: image/jpeg'); $im = imagecreatefromjpeg($img_url); imagejpeg($im); imagedestroy($im); ?> and the actual <img> tag resides on another page much thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.