curl IMAGE problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

curl IMAGE problem

Post by pedroz »

Dear coders,

I would be very glad if you could help me with this problem.
I cannot use cookies, sessions or html <img command and I would like to display an image while running index.php and keep executing the script but it stops when I include test.php. Any ideas to solve this ?

Thanks


Conditions:
// NO COOKIES, NO SESSIONS
// NO <img src=’teste.php?id=fox1’…


> FILE 1 index.php

Code: Select all

$id='fox1';

include ("test.php");
image_display($id);

// PROBLEM HERE! 
// code stops in the line above. doesn’t execute the lines below
echo "output: ".$id;
echo “THE END”;
> FILE 2 test.php

Code: Select all

function image_display($id){

$ch = curl_init("http://www.google.es/images/firefox/".$id.".gif");
if (!$ch) { die( "Cannot allocate a new PHP-CURL handle" ); }

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

$data = curl_exec($ch);
curl_close($ch);

header("Content-type: image/jpeg");
print ($data);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Choose one, either echo the text or the image. Images cannot be sent in the same stream as textual data.
Post Reply