Solved

PHP Graph giberish

Posted on 2006-11-07
5
249 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
ID: 17893498
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
ID: 17893507
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
ID: 17894005
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
ID: 17894103
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
ID: 17898593
Thanks!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mysql between clause 2 22
How to stop user from going back to a previous page in PHP 3 31
php checkbox validation 5 27
PHP AJAX Wordpress 9 19
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
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.

776 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