Solved

PHP Graph giberish

Posted on 2006-11-07
5
246 Views
Last Modified: 2012-05-05
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ÿÿÿHkHkÿÿªªªÿÿÿæü´àœIDATxœí]r£8F™½OOVЙô¤ŠuèE+p•÷¿„Aâ»2„€~¬ï$Ýq0âX÷ K€ºŽBi¥í·Ç ÿûçŒüšwgØo£W¿ÚÇfú×5ëÄ€KÓN´¾çÝ·Nlȸ+L{b'Aì(½J7°çÄ4A®Ý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ä†ltB'Æ"çØL÷Sz†Ÿ÷r; °Ýö&½“Þu -äw䥲\«R´“1vRyõ_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
0
Comment
Question by:Exceter
  • 3
5 Comments
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 500 total points
Comment Utility
Keep in mind that any graphing class like that is going to produce an image.  That means the correct way to insert it into a page is:

<img src="your-graphing-script-name.php" alt="Graph" />

And then put JUST the graph code into your-graphing-script-name.php

0
 
LVL 19

Expert Comment

by:VoteyDisciple
Comment Utility
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.
0
 
LVL 11

Expert Comment

by:Joseph Melnick
Comment Utility
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
0
 
LVL 19

Expert Comment

by:VoteyDisciple
Comment Utility
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.)
0
 
LVL 8

Author Comment

by:Exceter
Comment Utility
Thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now