Images in php
Moderator: General Moderators
Images in php
Hello. I want to store pictures in a database and then call them from php. I tried echo but it only shows a lot of weird characters. Can somebody help me? I gave to the picture the data type "longblob" is that correct? thanks!
Re: Images in php
You have to output a content-type header telling the browser what mime type the data uses, otherwise apache will default it to plaintext
Re: Images in php
lol! i am new at this!! can you explain how can i do all that?! thanks!
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Images in php
When you output an image you typically use the <img> tag.
So, what you can do is get the image's path from your database and output like so:
Obviously the image name should include the file type e.g. jpg or gif etc...
Get it?
So, what you can do is get the image's path from your database and output like so:
Code: Select all
<img src="your/image/path/<? echo $image_name; ?>" />Get it?
Re: Images in php
Except in this case "your/image/path/<? echo $image_name; ?>" will be the path to a script that fetches the image content from the database.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Images in php
If you fetch your db data beforehand then that would be more ideal 
Re: Images in php
How would you do that for an image stored in a database?aceconcepts wrote:If you fetch your db data beforehand then that would be more ideal
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Images in php
Before I explain anything lets see if we're all on the same page.
How is the images stored in the database?
How is the images stored in the database?
Re: Images in php
The original poster said they're in a LONGBLOB column, so lets assume they're in there as binary data.aceconcepts wrote:How is the images stored in the database?
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Images in php
I see, I didn't realise the picture was being store and retrieved directly. I thought the image was being stored in an images dir and referenced by path.
Re: Images in php
He could be I suppose. LONGBLOB is a bit of a strange choice of data type for a column storing a filename if that's the case though.aceconcepts wrote:I see, I didn't realise the picture was being store and retrieved directly. I thought the image was being stored in an images dir and referenced by path.
Re: Images in php
You never know, he could be storing a serialized object too.. point is generalized questions with generalized background on the info get generalized answers