Forums

PHP

This topic is locked

select image from DB... problems...

Posted 28 Aug 2001 07:25:59
1
has voted
28 Aug 2001 07:25:59 crazy larry posted:
Hello,

I get no errors, but the image is the text or ascii stuff that makes up the image.

I think I need to add one or both of these lines of code, but don't know where/why/how:
1) header("Content-type: image/gif";
2) <img src=images/$picture_name>

Also, where/how/what do I set the $Image_ID.

Here is my code:
<?php
// Copyright (c) Interakt Online 2001
// www.interakt.ro/

require("./../adodb/adodb.inc.php";
require("./../Connections/prague_ODBC.php";
?>
<?php
$select_iamge_test__MMColParam = "1";
if (isset($Image_ID))
{$select_iamge_test__MMColParam = $Image_ID;}
?>
<?php
$select_iamge_test=$prague_ODBC->Execute("SELECT Title, Image FROM image WHERE Image_ID = " . ($select_iamge_test__MMColParam) . "" or DIE($prague_ODBC->ErrorMsg());
$select_iamge_test_numRows=0;
$select_iamge_test__totalRows=$select_iamge_test->RecordCount();
?>
<html>
<head>
<title>select image test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>
<?php echo $select_iamge_test->Fields("Title"?>
</p>
<p>
<?php echo $select_iamge_test->Fields("Image"?>
</p>
</body>
</html>
<?php
$select_iamge_test->Close();
?>

-----------------------------------------
here is the output, when I run the code:

about_up.gif

GIF89aPÄ™ÌÌ™f²L&¢¦Ã}¼j@©0 œ s¶V³Æ†Z¯Cš¿s¿É¹_2¦&ŸM¬:½Å”€¹`)¥!þ!ù,Pÿ Ždižhª®lë¾pœtmßx®ï|Ï“¾ pHÄ‹=BÉÔ›GÖ8ÍÚ¢Ñ|""má¸fi1Ó[„–L`®‘„°À4"³ä64j*JÜ噟Xú ǤÑ,HY[p@ÂΧM¢Š©ù@B˜X™@ð•e¯ö,ù‚k ‡`׊$P) VDXÍ Žè‹5êbºX2¬a¢2"KžL¹²å!;




Replies

Replied 28 Aug 2001 09:56:46
28 Aug 2001 09:56:46 Bruno Mairlot replied:
This happens because,

the full image code is inside your DB.

To do that, the only way you have to output the image, is indeed to add

header("Content-type: image/gif";

but it's not enough, you need to print the image field, <b>AND NOTHING ELSE.</b>

This is extremely important, since you're not printing HTML page, but a image instead.

You can't have anything else printed on the page, because, your explorer will try to interprete this as a GIF code.

Move the echo $select_iamge_test-&gt;Fields("Image" just before the html tag, then erase everything.

But, this is not the best way to do that. You should store in your database, only the the path to your image, then show it with, a tag like this ;

&lt;img src="&lt;?php echo $select_iamge_test-&gt;Fields("Image"?&gt;" &gt;

while your image, is a regular image file.

"First they laugh at you, then they fight you, then you Win..." Ghandi
Replied 28 Aug 2001 20:18:28
28 Aug 2001 20:18:28 crazy larry replied:
Thanks for replying...
But I still have problems...

So, your saying to store the path of the image and not the actual image in the database. BUT, if you want to store the image in the database, when showing the image... you can only show the image and NOTHING else.

uhmmmm...

I have this code and I still get basically get the same result. What gives?

Thanks


&lt;?php
require("./../adodb/adodb.inc.php";
require("./../Connections/prague_ODBC.php";
header("Content-type: image/gif";

$select_iamge_test__MMColParam = "1";
if (isset($Image_ID))
{$select_iamge_test__MMColParam = $Image_ID;}

$select_iamge_test=$prague_ODBC-&gt;Execute("SELECT Title, Image FROM image WHERE Image_ID = " . ($select_iamge_test__MMColParam) . "" or DIE($prague_ODBC-&gt;ErrorMsg());
$select_iamge_test_numRows=0;
$select_iamge_test__totalRows=$select_iamge_test-&gt;RecordCount();

?&gt;
&lt;html&gt;
&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;?php
echo $select_iamge_test-&gt;Fields("Image"?&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
$select_iamge_test-&gt;Close();
?&gt;


Replied 28 Aug 2001 20:26:45
28 Aug 2001 20:26:45 crazy larry replied:
never mind... if only I followed your directions the first time.

I did move the line of code BEFORE the html and erase everything and I did work.

Thanks

So basically, if you want a html page with an image from a database, YOU HAVE TO USE paths. There is no way around that????

Is that correct? that seems wrong. Why would you want to store images in a database if you can show them in a regular HTML page?

Here is my thinking:
I want images in the database for easy of dealing with. You can view them when ever, search on them... always know where they are at.
I also want to be able to show the images on a web page, but not at the expensive of the "image" being the ONLY thing on the web page.

I guess my solution is to store both, the image and the path. In situations when I can have the image being on the page by itself, use the image in the table.

When I need to show the image and have other text on the page, use the path.

THanks

Replied 28 Aug 2001 21:22:38
28 Aug 2001 21:22:38 crazy larry replied:
Different IDEA....

Help please....

I tried this for a solution, but I have something wrong, not sure what it is.

I have this PHP script in a file called GetImage.php:

&lt;?php
require("./../adodb/adodb.inc.php";
require("./../Connections/prague_ODBC.php";
header("Content-type: image/gif";

$select_iamge_test__MMColParam = "1";
if (isset($Image_ID))
{$select_iamge_test__MMColParam = $Image_ID;}

$select_iamge_test=$prague_ODBC-&gt;Execute("SELECT Title, Image FROM image WHERE Image_ID = " . ($select_iamge_test__MMColParam) . "" or DIE($prague_ODBC-&gt;ErrorMsg());
$select_iamge_test_numRows=0;
$select_iamge_test__totalRows=$select_iamge_test-&gt;RecordCount();

echo $select_iamge_test-&gt;Fields("Image";

$select_iamge_test-&gt;Close();
?&gt;


On my regular html/php page, I have this code:

&lt;img src="GetImage.php?Image_ID=5"&gt;


It does not work (ie. does not show the image). I do not get errors, but can't figure out why it is not working.

I got the idea from
www.phpbuilder.com/columns/florian19991014.php3?page=3

What is different?
Should I create a GetImage function?

THanks

Reply to this topic