Image Output

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

Post Reply
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

Image Output

Post 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()?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

Post by RadixDev »

I can read the image data from PHP into a variable but how do I acutally put that onto a HTML page?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

So I'd have to output it to a directory temporaly? Or use PostgreSQL... How does it do in PostgreSQL though?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

Post by RadixDev »

Found the post... sorry didn't look hard enough last time :oops:
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 »

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 »

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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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 »

got it u don't need stripslashes!!! Cheers feyd again! :D
Post Reply