Page 1 of 1
Displaying images in a drop down menu
Posted: Thu Mar 24, 2005 9:16 am
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!
Posted: Thu Mar 24, 2005 9:24 am
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.
Posted: Thu Mar 24, 2005 9:29 am
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?
Posted: Thu Mar 24, 2005 9:40 am
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..
Posted: Thu Mar 24, 2005 9:44 am
by mattcooper
Javascript then?
I think I was trying to keep things too simple, but in reality was opening a can of worms!
Posted: Thu Mar 24, 2005 9:51 am
by feyd
yes, a bit of Javascript and CSS..