I am trying to create an image gallery, such as when you click an image in Getty Images
http://www.gettyimages.com/Search/Search.aspx?EventId=96396247&EditorialProduct=Sport
Ima开发者_StackOverflow中文版ge: http://tinypic.com/r/efffvs/6
I am just looking to get a next and previous for the gallery. Also that the details underneath are changed to match the image.
No database available.
Thanks for your help.
Laurence
Not familiar with Getty, but if you put your images in directories on your sever you can use PHP to get a directory listing and then loop through that listing to display the images.
$root = "/home/www/files";
if ( $handle = opendir("{$root}/altered/") )
{
## SME 05/21/2009 LOOP THROUGH THE DIRECTORY AND GET A LIST OF FILES THAT ARE NOT '.' OR '..'
while( ( $file = readdir( $handle ) ) != FALSE )
{
if( $file != '.' && $file != '..')
{
//DO SOMETHING WITH FILE
}
}
closedir($handle);
}
If you want to get fancy with it you could even write an XML file with image information and put it on the server, then parse the XML when you load the images to supply meta data such as file names, who uploaded the file, etc.
Even if you don't have a database (i.e. MySQL, PostgreSQL, ...) server available, you should be able to use an SQLite database : the engine is incorported into PHP (via an extension that's generally enabled), and the whole database is stored as a file.
It sounds like the simplest solution if you already know how to develop a PHP application, and generally do so using a database as a data store.
(Of course, you could also just iterate over the filesystem, using either readdir
or DirectoryIterator
-- but using a database might make a couple of things easier, like storing additionnal meta informations, for instance)
For more informations :
- PHP documentation : SQLite, SQLite3 -- and there is also a PDO driver.
- SQLite website
You can use the example php.net gives for opendir()
to loop through the files in a directory to build an array and do what you're asking.
You can then use read_exif_data()
to read the image file description, title, etc. for below the image. This assumes the image files have exif data to read and your php installation supports exif.
精彩评论