Image gallery like Getty Images but with no database

邮差的信 提交于 2019-12-11 09:44:56

问题


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

Image: 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


回答1:


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.




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/2283495/image-gallery-like-getty-images-but-with-no-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!