By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,718 Members | 1,349 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,718 IT Pros & Developers. It's quick & easy.

How can I access an image from mysql

P: n/a
Hi,

I have this script:

<?php
mysql_connect("host", "user", "pass");

mysql_select_db("database");

$query = "select * from table";
$result = MYSQL_QUERY($query);
while($myrow=mysql_fetch_array($result)){
echo "<img src=".$myrow['bin_data']."><br>";
};
?>

I can't get the output from the "bin_data" to show as an image ( which it
is ).
Can anyone tell me what's wrong?

Ricki
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Ricki Susic wrote:
Hi,

I have this script:

<?php
mysql_connect("host", "user", "pass");

mysql_select_db("database");

$query = "select * from table";
$result = MYSQL_QUERY($query);
while($myrow=mysql_fetch_array($result)){
echo "<img src=".$myrow['bin_data']."><br>";
};
?>

I can't get the output from the "bin_data" to show as an image ( which it
is ).
Can anyone tell me what's wrong?


You have to send the correct MIME Type header.
Matthias

Jul 17 '05 #2

P: n/a
I noticed that Message-ID: <bn************@ID-16734.news.uni-berlin.de>
from Matthias Gutfeldt contained the following:
$result = MYSQL_QUERY($query);
while($myrow=mysql_fetch_array($result)){
echo "<img src=".$myrow['bin_data']."><br>";
};
?>

I can't get the output from the "bin_data" to show as an image ( which it
is ).
Can anyone tell me what's wrong?


You have to send the correct MIME Type header.


I find it easier to store the image elsewhere and just save the path in
the db.

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3

P: n/a
Geoff Berrow wrote:
I noticed that Message-ID: <bn************@ID-16734.news.uni-berlin.de>
from Matthias Gutfeldt contained the following:

$result = MYSQL_QUERY($query);
while($myrow=mysql_fetch_array($result)){
echo "<img src=".$myrow['bin_data']."><br>";
};
?>

I can't get the output from the "bin_data" to show as an image ( which it
is ).
Can anyone tell me what's wrong?


You have to send the correct MIME Type header.

I find it easier to store the image elsewhere and just save the path in
the db.


Me too. But that's not what he's doing.
Matthias
Jul 17 '05 #4

P: n/a
>You have to send the correct MIME Type header.
Matthias

Can you tell what that is?

Ricki
Jul 17 '05 #5

P: n/a
Hello,

To use an image, you nead a header-information.
You can't create an image in a file you are using.
Just use an other file that takes the image-data and sets a header
like "header("Content-Type: ...");

Than you can use the image by using filename.php?img=DB-ID

sorry, my english is not very good :)

Kilian
Jul 17 '05 #6

P: n/a
Ricki Susic wrote:
You have to send the correct MIME Type header.
Matthias


Can you tell what that is?


The important thing to note about image creation: The PHP code that
creates the image has to be in a file on its own, which is then called
from the page: <img src="php-created-image.php">. You can't "echo" the
image date right into the src attribute.

Check the PHP manual: <http://ch.php.net/manual/en/ref.image.php>.
There's a simple example for a PNG graphic, and an explanation how to
use it.
Matthias

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.