Well I having headaches from last 3 days. So finally decided to post it here. I have made a page in which there is some content. <?php echo $content; //images code //Now the dynamically created graph print_image(); ?> PHP: The above thing is a simplified version of my script. Now what happens is that whenever I test the code without echo on the top line then the graph which is dynamically created is shown. But my website needs the content on the top and not after the image. The problem is with the header() thing. I had mentioned header ("Content-Type: image/png"); But the headers are already sent so is there a way to modify or send new headers in that same page? Please let me know. Thanks.
I think you would be better keeping the content and the image in seperate scripts. <?php echo "content"; include("imagescript.php"); ?> PHP: Or if that fails just echo the image using <img src="imagescript.php">
AFAIK one page can only have one header, else how does the browser know how to interpret it? Looks like the print_image is meant to output a picture on its own (separate page), not inline amongst content. Seems to me you will have to alter that function - code a variation that just echoes the image html, no headers.
I tried the code in other page too. But then it shows me the binary data of the PNG as a text instead of PNG image.
I tried to post the code but it is too long. Here is the thing I am using to generate the graphs dynamically from the arrays http://www.qualityunit.com/postgraph/
I agree with mad4: have you tried using it as an 'img src'? HTML is HTML, no matter how you generate it. When doing things like this you have to work out how the HTML is going to look in the end. Have you ever seen an image with its actual 'binary source' embedded in the HTML? No. You have the HTML use the image tag with the src attribute. This doesn't (can't!) change, just because you're using PHP. You need to have your content in HTML which also creates an image link back to the output of your print_image function.
Yes TwistmyArm I checked it out. And I am a developer from last 2 years. I know that basics. But what my problem is that this kind of images can be generated dynamically Bcoz it is graph. In example also the graph is showing but When I even echo "HI" above (Means before the image) PHP sends out default headers and it prevents my dynamic image to be displayed properly (Or can be said not display it at all)
Try this. Put the <?php print_image(); ?> in a separate file and call it graph.php. Now under echo $content; just type: <img src="graph.php"> The print_image function seems to send headers saying it is an image. Treating it as one could fix it.
T0PS3O is exactly right and that's what both myself and mad4 have tried to say (just not as straight forward as that, I guess!). Nick_Mayhem: I appreciate that you may be a programmer but you're still confusing your outputs. Even if PHP didn't send a header before the string 'HI', you'd still be wanting PHP to send an image with a separate string that isn't part of the image before it. In effect, you would end up with the image data but with the letters H and I at the start of the image 'source'. Surely you can see that that effectively would create an invalid image anyway? Anyway, do exactly as T0PS3O says and you won't have a problem.
WOWO DP rocks. I figured it out. it took 13 different PHP files to work it around. But at last it is done. HE EHEH. I am so happy.
Nick_Mayhem: Again, not knowing your exact situation, but don't forget that you can still pass in parameters to the image code via GET. If your 13 scripts are 'pretty close' to each other, you might want to look at doing that. Something along the lines of: <img src="/path/to/script.php?param=x&other_param=y"> for example. That way, you can keep the common code and just use switch / ifs for the non-common stuff. Glad to hear you've got it working though!
Thanks. The code was much complicated then explained above. It needed some parameters like graph values, title, yaxiz ticks, x axis numbers or labels, transperent color, background color, bar color, numbers and title color, my copyright notice to be printed on it. Etc etc. But it was fun doing it at last. And thanks to all of you for your help and suggestions. Thanks a lot.
its not possible to put image drawing code and text on the same page due to context-type simple enough do this <?php echo "content"; echo "<img src=\"draw_image.php?params=1gs\">"; ?>