Using a db for photos

penguinmama

12.***.***.***
2,062 days ago

Using a db for photos

I have a real estate application I am attempting to develop, that involves needing to view one or more photos of a property inline in the property listing. Logically, they are in a separate table. However, I can't figure out how to access them to display in the listing. Any ideas?

sheeri

70.***.***.***
2,050 days ago
Somehow you have to tell the browser that the data you're giving it is an image. Browsers use the <IMG SRC="'> tag to display an image on the same page as text, and the SRC="" contains a URL. So you have to make a page that will display the data as an image, and then refer to that page in the SRC attribute of the IMG tag.

http://www.phpriot.com/d/articles/database/images-in-mysql/page8.html

probably has what you need. You might want to start at the beginning of the tutorial to understand what his table names and such are, to line the code up with your own. But the code is very well commented, and it's a very small script that sends a header to the browser that "this page is an image" and then puts the data on it.

Hope that helps!

-Sheeri
http://www.sheeri.com

penguinmama

12.***.***.***
2,044 days ago
Thanks, Sheeri!

I should have come back and updated - I forgot to. I figured out how to have it store the image in a separate directory and just save the location in the database, so I can use a regular image tag to call it.

Thank you for your help, anyway!

Bradd

203.***.***.***
2,036 days ago

penguinmama;106:

I have a real estate application I am attempting to develop, that involves needing to view one or more photos of a property inline in the property listing. Logically, they are in a separate table. However, I can't figure out how to access them to display in the listing. Any ideas?


I have done a lot of work in databases and specificaly in oracle so it is not a good idea to store omage objects in database because these maje databse very heavy so it is good approach to give llinks or paths to that images leaving those on some hard disk space !

sheeri

209.***.***.***
2,036 days ago

Bradd;312:

I have done a lot of work in databases and specificaly in oracle so it is not a good idea to store omage objects in database because these maje databse very heavy so it is good approach to give llinks or paths to that images leaving those on some hard disk space !


What version of Oracle? See http://www.oracle.com/technology/products/intermedia/htdocs/why_images_in_database.html

Databases have gotten a lot better over the years. We had to put our images in a database because we had too many files and folks were accessing them too much, and the filesystem couldn't keep up.

Plus, if you're a site that wants to have more than one webserver to balance the load, you'd either have to copy the images to each webserver, or do something like NFS mount the image directories....not pretty.

mtajim

202.***.***.***
1,941 days ago
Put up your image in separet folder and call it through php. Dont use db for images, it becomes too bulky

sheeri

146.***.***.***
1,941 days ago

mtajim;390:

Put up your image in separet folder and call it through php. Dont use db for images, it becomes too bulky


mtajim, have you actually tried this? Filesystems have overhead too, and we've actually found that using the database is less bulky for our 6 million images. Plus then there's the added benefit of not being able to associate the images with metadata -- if a customer is removed from the system, their images do not get removed with them.

It used to be that databases couldn't handle large data like that. But nowadays, what's the difference between putting 1MB of text in a BLOB or 1 MB of an image? nothing!!!!

Putting the images in a webserver is one possibility, but databases and computers are robust enough that putting them in the database just like any other data is acceptable, and even encouraged, these days.

Even oracle recommends it.

HTML code:

http://www.oracle.com/technology/products/intermedia/htdocs/why_images_in_database.html