Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP Graph giberish

Posted on 2006-11-07
5
Medium Priority
?
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

604 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