Page 1 of 2

Trouble Displaying Images using PHP Script

Posted: Sat Aug 11, 2007 1:23 pm
by slade27
Greetings,


I am a php newbie, but I have successfully created two different kinds of scripts so far: one that generates links with info pulled from a database, and one that creates an image "on the fly" using info pulled from a database.

My problem is, I am now trying to include the two operations in one script, and whenever I do, the image portion of the script just creates a lot of gobbledy-gook text.

I thought at first that it was a header problem, since I was originally getting header error messages, but the header error messages, at least, stopped after I added the following html code to the very top of my php script:


<meta http-equiv="content-type" content="multipart/mixed; charset=utf-8" /></meta>


Nevertheless, my browser still returns garbage when it reaches the part where it should be generating an "on the fly" image for me.


Below you will find what I think are the relevant portions of the script. Thanks in advance for any ideas on how to get it to work!

Brian
Alexandria, Virginia


Code: Select all

<html>
<head>
<meta http-equiv="content-type" content="multipart/mixed; charset=utf-8" /></meta>
</head>
<?php 

$result=mysql_query ("SELECT * FROM `Articles`
ORDER BY  `Title`");

while ($row = mysql_fetch_assoc($result)) {

echo $row['Title'];



//And now the image part that I can get to work on its own, but not here:


$Title = $row['Title'];



$im     = imagecreatefromjpeg("myimage.jpg");
$orange = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

imagestring($im, 5, 90, 115, $Title, $orange);

$x1= "77";
$y1="43";
$size="10";

$x2 = $x1+$size;
$y2 = $y1+$size;

imagefilledrectangle ( $im, $x1, $y1, $x2, $y2, $black );
imagejpeg($im);
imagedestroy($im);

}
?>

Posted: Sat Aug 11, 2007 1:51 pm
by forum.samir
I think this is a header problem. Please just remove the following lines from the script

<html>
<head>
<meta http-equiv="content-type" content="multipart/mixed; charset=utf-8" /></meta>
</head>

Posted: Sat Aug 11, 2007 2:09 pm
by slade27
When I remove that html text, I still get stuff like this at the point where the on-the-fly image should appear:




�����JFIF���������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ���C� $.' ",#(7),01444'9=82<.342���C 2!!22222222222222222222222222222222222222222222222222�������"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br�

Posted: Sat Aug 11, 2007 2:19 pm
by nickvd
you need to send the appropriate header() to inform the browser that you're sending it an image.

Posted: Sat Aug 11, 2007 2:20 pm
by kaszu
You are outputing titles, so header becomes "text/html" i think, that's why you see garbage, which in-fact is image (string of bytes).
This page is a simple html page or will it be an email?

Posted: Sat Aug 11, 2007 2:43 pm
by slade27
I added the following immediately before the php portion, but I still get junk when I reach the portion where the on-the-fly image is referenced.

<html>
<head>
<meta http-equiv="content-type" content="html/text; charset=utf-8" /></meta>
</head>

I am not working with e-mail. I am hoping to use this script eventually as an include to generate a list of links alongside a list of related on-the-fly images, both links and images to be created from data pulled from the same database.

The scripts, as I say, both work on their own, but the text comes out garbage when they are combined.

Posted: Sat Aug 11, 2007 2:50 pm
by nickvd
Did you read the manual page for the header() function? I'm nearly 100% sure it will contain the solution you are looking for...

"Give a man a fish..." versus "Teach a man to fish..."

Posted: Sat Aug 11, 2007 2:57 pm
by slade27
I'll give it a shot. I've read dozens of pages about appropriate header usage, however, over the last three hours -- MIME sounds like what I need, but everyone talks about it only in the context of e-mail.

Posted: Sat Aug 11, 2007 2:59 pm
by nickvd
I think you're confusing <head></head>'ers with true http headers...

A simple google search could help. 'http image headers'

http://www.google.ca/search?q=http+image+headers

Posted: Sat Aug 11, 2007 3:04 pm
by slade27
I'll keep trying then, but I'm obviously missing something basic and perhaps rather simple, so if anybody can "pick it out" I'd appreciate it, as I've been working on this problem all morning and have already searched the recommended topics extensively.

Don't get me wrong: I'm not saying that the info isn't out there, even easily so, but I'm somehow managing either to miss it or to misunderstandi it. So again, if somebody has any more specific ideas, I'd welcome it.

In the meantime, I'll go back to the Google drawing board as suggested.

Posted: Sat Aug 11, 2007 7:29 pm
by superdezign
slade27 wrote:I'll keep trying then, but I'm obviously missing something basic and perhaps rather simple, so if anybody can "pick it out" I'd appreciate it, as I've been working on this problem all morning and have already searched the recommended topics extensively.
Extensively? Really?

Code: Select all

header('Content-Type: ????');
Headers for files are NOT HTML. Headers in files define the type of file, the size of the file, etc. You only NEED to tell the browser the type of the file, and it'll decipher the rest.

Headers. No HTML, just headers.

Posted: Sat Aug 11, 2007 9:08 pm
by slade27
I don't have any witnesses: I'm sorry you find it so hard to believe that I'm not as smart as you.

If you don't want to answer my question, DON'T.

JESUS CHRIST!

Posted: Sat Aug 11, 2007 9:09 pm
by slade27
ADIEU to this FORUM

GROW UP

Posted: Sat Aug 11, 2007 9:11 pm
by slade27
Sorry. I though this was a forum to find help. Seems it's just a forum to have one's integrity impugned and then condescendingly told to beat it.


MOROn!@J@JN:KLE'cb,./ xcvdb ZXVçΩ

Posted: Sat Aug 11, 2007 9:13 pm
by slade27
Maybe the fact that nobody can help me out shows that it's not the easiest question in the world -- why don't you rant against the people who couldn't help me with this easy problem