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
RadixDev
Forum Commoner
Posts: 66 Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.
Post
by RadixDev » Sat Aug 28, 2004 4:48 pm
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()?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Aug 28, 2004 5:01 pm
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..
RadixDev
Forum Commoner
Posts: 66 Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.
Post
by RadixDev » Sat Aug 28, 2004 5:09 pm
I can read the image data from PHP into a variable but how do I acutally put that onto a HTML page?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Aug 28, 2004 5:21 pm
you can't. Images are seperate data streams from HTML data.
RadixDev
Forum Commoner
Posts: 66 Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.
Post
by RadixDev » Sat Aug 28, 2004 5:23 pm
So I'd have to output it to a directory temporaly? Or use PostgreSQL... How does it do in PostgreSQL though?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Aug 28, 2004 5:26 pm
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..
RadixDev
Forum Commoner
Posts: 66 Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.
Post
by RadixDev » Sat Aug 28, 2004 5:39 pm
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...
RadixDev
Forum Commoner
Posts: 66 Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.
Post
by RadixDev » Sat Aug 28, 2004 6:10 pm
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?
RadixDev
Forum Commoner
Posts: 66 Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.
Post
by RadixDev » Sat Aug 28, 2004 6:24 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Aug 28, 2004 6:28 pm
viewtopic.php?p=107457
you don't return the image via the header..
RadixDev
Forum Commoner
Posts: 66 Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.
Post
by RadixDev » Sat Aug 28, 2004 6:58 pm
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 "?
RadixDev
Forum Commoner
Posts: 66 Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.
Post
by RadixDev » Sat Aug 28, 2004 7:02 pm
got it u don't need stripslashes!!! Cheers feyd again!