Exceter
asked on
PHP Graph giberish
I've tried 2-3 different PHP graph classes from this MB thread,
http://www.phpbuilder.com/board/showthread.php?t=10302425
The examples work perfectly if I run them at the very top of my source files but then, only the graph is displayed. It's as if page execution stops after the graph is displayed. When I try to insert the graph into a page I get giberish. They all result in something similar to this,
‰PNG IHDR&JÛ>‰ÉPLTEÿÿÿHkH kÿÿªªª ÿÿÿæü´àœI DATxœí]r£ 8F™½OOVÐ ™ô¤ŠuèE+p •÷¿„Aâ»2 „€~¬ï$Ýq0 âX÷ K€ºŽBi¥í·Ç ÿûçŒüšwgØo£W¿ÚÇfú×5ëÄ€KÓN ´¾çÝ·Nlȸ +L{b'Aì (½J7°çÄ4 A®ÝyåÄ´<» Nò-ÎÉð…N Ì”OÚÓ2³½râ¢E -´ý×MuCè6cä%ªÕÊ@!„B!„T „íÓÉ]†ÂP× f§Æ¥XQ6(í œüj”ˆ”©žüõ Õ è,9–Nf涘N:¡ t‚Ð B' t‚Ð B' t‚Ð B' t‚Ð ëgSãÙÿtâqÔì£+û¨7h÷í€>r19²:¬'A5¡¨&c:¡“ÅÉÐÓI :¡ t‚Ð B' t‚Ð B' t‚Ð B' t‚Ð =·œc!vÌKÑ Xáu[´â˜—<¬'›jÒñ¼¨&Û[Iè$B~'ýãë™x“Å;yôý×#í& ‹wòÕÑÉ–‡µ ’”⤯&³% ßå8¿“ç³fŠ ÈŸó;É€w ¹Û Љƒ±ƒÐ R|[œ¥-3JV'ÿ}†¤Únɱ“ÛIä†l tB'Æ"çØL ÷Sz†Ÿ÷r; °Ýö&½“Þu -äw䥲\«R´“1vRyõ_9Q:̱ ™®óz”ì$Ïu^ ¶ó¨¤Ÿ¨®ˆkßr; ò‰2¦„±ÑüNDwÂÏÅž%ŸðØÞÃÏ€Èä $6‹e2'›Ýÿ× .Ëï$o>)ÐIö ±ŒDhÚIdJ ö¦0Ÿ,,ù„N ”ß~cÜ„ãáÂt c§•¾íoî‘îÜ#ÜÂÎ/|G¼“áuâ>‘¹š0 ü°Ï-?üscìø …oÉtÀèj€¶û =§ £ìÂq]©5'v''“WA:_‘šr2ÅÎ& >:ŒÑ‰Í)n œØ½õÑ"æX· `TcÜöÆ×™Ö ¡„N!„BH „ÿÐ'Šô=º) ÎIEND®B`‚
This looks to me as if the raw file is being displayed as opposed to being interpreted. The question is, why?
Cheers!
Exceter
http://www.phpbuilder.com/board/showthread.php?t=10302425
The examples work perfectly if I run them at the very top of my source files but then, only the graph is displayed. It's as if page execution stops after the graph is displayed. When I try to insert the graph into a page I get giberish. They all result in something similar to this,
‰PNG IHDR&JÛ>‰ÉPLTEÿÿÿHkH
This looks to me as if the raw file is being displayed as opposed to being interpreted. The question is, why?
Cheers!
Exceter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To get a feel for why, what you've effectively done is opened up an image file in Notepad, and copied & pasted the contents of that file into your HTML document. Of course that's not how you'd really insert an image on a page; you'd use an <img /> tag. The fact that this particular image happens to be generated by a script changes nothing.
Hello Exceter,
The problem with your graphing function is that the browser does not know what kind of content you intend to send it so it just output the binary. Your function needs to output the appropriate header to identify the content.
<?php
// no space above php or this may still fail.
header('Content-Type: image/png');
echo $png_data_here;
?>
Joseph Melnick
The problem with your graphing function is that the browser does not know what kind of content you intend to send it so it just output the binary. Your function needs to output the appropriate header to identify the content.
<?php
// no space above php or this may still fail.
header('Content-Type: image/png');
echo $png_data_here;
?>
Joseph Melnick
Check the documentation for the graphing class you're using though -- usually you don't have to output any headers of your own; just calling the draw() or stroke() method (or whatever it is that makes the graph draw) will deal with the Content-Type header on its own. I doubt that's something you have to worry about, especially since when you view the graph on its own it seems to be displayed right. (That's no guarantee, though, since browsers do sometimes try to be smarter than the headers they receive. Check the documentation to make sure.)
ASKER
Thanks!