Page 1 of 1
Image Output
Posted: Sat Aug 28, 2004 4:48 pm
by RadixDev
If I upload an image to MySQL database (BLOB) how do I output it to an HTML page?
Basically I know you can do this by using pg_lo_read_all() in PostreSQL but how do I do it in MySQL? Send it through header()?
Posted: Sat Aug 28, 2004 5:01 pm
by feyd
you'd need to make a downloader script that will query for the image in the database.
we've talked a bit about this in the past. I believe the thread I'm thinking of is in the Theory forum..
Posted: Sat Aug 28, 2004 5:09 pm
by RadixDev
I can read the image data from PHP into a variable but how do I acutally put that onto a HTML page?
Posted: Sat Aug 28, 2004 5:21 pm
by feyd
you can't. Images are seperate data streams from HTML data.
Posted: Sat Aug 28, 2004 5:23 pm
by RadixDev
So I'd have to output it to a directory temporaly? Or use PostgreSQL... How does it do in PostgreSQL though?
Posted: Sat Aug 28, 2004 5:26 pm
by feyd
feyd wrote:you'd need to make a downloader script that will query for the image in the database.
we've talked a bit about this in the past. I believe the thread I'm thinking of is in the Theory forum..
Posted: Sat Aug 28, 2004 5:39 pm
by RadixDev
Found the post... sorry didn't look hard enough last time
viewtopic.php?t=24895&start=0&postdays= ... highlight=
So I could make a page which sends image using the header() function and
link on the original page like this...
Code: Select all
<img src="getImage.php?user=username">
Would this work then? I'm givin it a try at this script now but haven't reach this point yet...
Posted: Sat Aug 28, 2004 6:10 pm
by RadixDev
How do I add binary data to Mysql db... I tried the normal way but the file had ' and " so it didn't work... Do I have to use addslashes() then? Is there any other way?
Posted: Sat Aug 28, 2004 6:24 pm
by RadixDev
Done that... but now I'm confused when I try to show the iamge I do this...
Code: Select all
<?php
header("Content-type: ".$image['type']);
header(stripslashes($image['image']));
?>
But on the page it does not show the image but a cross. I know that the second line is wrong... what do i put there?
Posted: Sat Aug 28, 2004 6:28 pm
by feyd
viewtopic.php?p=107457
you don't return the image via the header..
Posted: Sat Aug 28, 2004 6:58 pm
by RadixDev
Code: Select all
<?php
header("Content-length: ".$image['size']);
header("Content-type: ".$image['type']);
echo stripslashes($image['image']);
?>
Still this won't work... is it because of the stripslashes, if it is how do I make sure that when adding image to the database, i can convert ' and "?
Posted: Sat Aug 28, 2004 7:02 pm
by RadixDev
got it u don't need stripslashes!!! Cheers feyd again!
