Jump to content

photo gallery php/mysql question


music_lp90

Recommended Posts

Hi, I'm pretty new to php, but I have two people who are asking me to build sites for them that will have photo galleries. I am able to load pictures into a MySQL database, but I'm uncertain of how to retrieve the thumbnail images, display them in a html table and link them to the larger images they represent. Can someone tell me what I need to research in order to do this? Would it be some type of query followed by pagination (which I know nothing about)?Thanks.

Link to comment
Share on other sites

Well, then it depends on the database. You can read the binary data straight from the database, send the correct content-type, and print the data if the image is in the database. Otherwise you would just get the filename and write a link to the image. In either case, the parent (larger) image should be stored in the same record as the thumbnail so that you know which image the thumnail links to.If you have the binary data in a field called "thumb", and it is a jpeg, you would display it like this:

<?php$sql = ...$result = mysql_query($sql);$row = mysql_fetch_assoc($result);header("Content-type: image/jpeg");header("Content-length: " . strlen($row['thumb']));echo $row['thumb'];?>

Link to comment
Share on other sites

Ok, I'm going to try this way. I've got sort of what I wanted to do working without using the database, but I want to try it this way and see if I can get it to work and then try to do pagination so it will display only a certain number of images per page. Thanks for the help.Here's how I had the table set up:`id` int(11) NOT NULL AUTO_INCREMENT, Primary Key `title` varchar(64) character SET utf8 NOT NULL,`ext` varchar(8) character SET utf8 NOT NULL,`image_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,`data` mediumblob NOT NULL, I'll add a thumb field, do I make the thumb field a medium blob as well?

Link to comment
Share on other sites

just make one column called data like you have, and duplicate it with a different name. Then you can resize it with something like the gd library and put that into the database also.

Link to comment
Share on other sites

Actually, you don't even need to store the thumbnail in the database if you don't want to. You can just read the full-size image and resize it to whatever size you want when you display it. It's a little complex, but you can do it.Also, if you aren't sure how to get the image data in the first place, you can use the results of the file_get_contents function to store in the database. All you need is a string containing the file data, and that function will give it to you. You can also use fopen and fread.If you want to see an example of a gallery that stores images in the database and resizes and things like that, download this:http://www.manchine.net/steve/files/gallery.zip

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...