PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
maniac9
Forum Commoner
Posts: 55 Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:
Post
by maniac9 » Mon Oct 20, 2003 10:44 pm
I've followed some links given here and gotten GD stuff to work - at least I thought...
this page -
http://public.radicant.net/motr_keystrokes.php - works when viewed by itself, but it doesn't when i try to include it as an image in html...here's the code
PHP -
Code: Select all
<?php
// open stats file
$file = fopen("http://pulse.whatnet.org/api/user.php?account=motr", "r");
// skip to number file
fgets($file);
fgets($file);
fgets($file);
fgets($file);
fgets($file);
fgets($file);
fgets($file);
fgets($file);
$Keystrokes = explode(" ", fgets($file));
// close stats file
fclose($file);
// create image
header ("Content-type: image/png");
$img_handle = ImageCreate (220, 18) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 67, 64, 58);
ImageTTFText ($img_handle, 8, 0, 5, 12, ImageColorAllocate ($img_handle, 143, 137, 127), "/WINDOWS/Fonts/Verdana.ttf", $Keystrokes[2] . " keystrokes and counting...");
ImagePng ($img_handle);
?>
HTML -
Code: Select all
<img src="http://public.radicant.net/motr_keystrokes.php" alt="" />
Any ideas?
maniac9
Forum Commoner
Posts: 55 Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:
Post
by maniac9 » Fri Oct 24, 2003 7:57 am
any ideas?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Oct 24, 2003 8:47 am
Do you have any! output in that script before
header ("Content-type: image/png"); ? It seems like the script is not able to set the content-type, it ships as text/html (the default).
What happens if you try
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
// open stats file
$file = fopen("http://pulse.whatnet.org/api/user.php?account=motr", "r");
...
maniac9
Forum Commoner
Posts: 55 Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:
Post
by maniac9 » Fri Oct 24, 2003 8:54 am
That seemed to change something - the image seemed to load faster by itself (at least it seemed that way) - but it still won't load inside any html, it just displays a good ol' X
is there something i'm just doing wrong?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Oct 24, 2003 9:28 am
what does the complete script look like?
if <?php is the beginning, what's the linenumber?
maniac9
Forum Commoner
Posts: 55 Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:
Post
by maniac9 » Fri Oct 24, 2003 11:37 am
that is the complete script - left out the last ?> by accident
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Oct 24, 2003 12:07 pm
and <?php is really in the first line, no blank line, no space, nothing before it in the file?
I've tested the script here, works fine for me
maniac9
Forum Commoner
Posts: 55 Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:
Post
by maniac9 » Fri Oct 24, 2003 12:12 pm
nope, nothing before it...maybe something to do with apache?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Oct 24, 2003 5:49 pm
hm, something that prevents php from sending the content-type....
is php installed as module or cgi (and btw: which version is it?)?
any auto_prepend_file directive?
...not much I can think of
maniac9
Forum Commoner
Posts: 55 Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:
Post
by maniac9 » Fri Oct 24, 2003 5:55 pm
right now its installed on apache as a module - version 4.3.3 with the latest version of apache
I think im going to try it on IIS in a bit, see if I get some other kind of result
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Fri Oct 24, 2003 6:41 pm
The above worked locally at home, and at one of my hosts. I had some problems on a third host, but found that spaces in the path to the .ttf was making it fubar, so bypassing it using dirname(__FILE__) I did...
http://phpdn.jam.nu/GDWhatpulse/ (working incl. source)
Not sure this is what causes your problem, but... Worth mentioning.