Displaying images in a drop down menu

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
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Displaying images in a drop down menu

Post by mattcooper »

Hi!

I'm trying to write an "image selector" script that will display thumbnails of images that are stored in a database. Drawing a blank everywhere I look at the moment...

So, the menu needs to pull out the images from the DB, shrink them to thumbnails and display the image name next to it. The value of the image displayed needs to be sent as it's URL when the form is submitted.

This is probably very simple, but I'm quite new to PHP so please forgive me...

Thanks in advance for your help and input!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

storing images in a database is typically a no-no. This is mostly due to the overhead required to fetch several images. Each image is sent in a seperate stream, thus each image requires a database query, the database server loading the data into memory, transferring to php and sending on to the user. If the image is quite large, this may result in memory overloads. The same goes for thumbnails, instead of fetching the image new every time to shrink it, why not cache the resulting thumbnail on server?

I'd also suggest not sending the full url as it's form value, as that could allow someone to inject their own remote image into the server. Instead, simply reference the image by identifier or something similar. In the database, I'd keep path information to the major file (at least filename), and potentially the thumbnail too.
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

Thanks Feyd, I thought that the image/database thing would be out of bounds. So, let's assume that there is a directory for thumbnails, which have been dynamically generated (how??!). I need the drop down menu to display them.

This is for dynamic website generation.. The first option I'm giving users is to choose a header image for their pages. I thought about foing it with a thumbs gallery, but I'm keen to keep this compact.

Can drop down menus actually display images?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

technically, it's possible, using CSS background-image attributes on each option. However, if the list is too large for the display, you will have problems. What I would do instead is fake a drop down that in reality is a simple floating pane. This will allow you to add html into it as well, so you could potentially have a 3 x 3 grid or something..
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

Javascript then?

I think I was trying to keep things too simple, but in reality was opening a can of worms!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, a bit of Javascript and CSS..
Post Reply