August 3, 2007
Super simple PHP gallery 3
find more posts in: phpJust save this as index.php and put it in a directory with a bunch of images. Images are displayed one per page (newest images first), and clicking on an image takes you to the next one.
<? exec("ls -r|egrep -i \"\.(gif|jpg|jpeg|png)$\"", $files); $files = array_reverse($files); $request = $_SERVER["QUERY_STRING"]; if(!(is_numeric($request) && $request > 0 && $files[$request - 1])){ $request = count($files); } $r_index = $request - 1; $next = $r_index; if($next==0 || !$files[$next-1]){ $next = count($files); } ?> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>my image gallery</title> <style type="text/css" media="screen"> a img{ border:0; } </style> </head> <body> <table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%"> <tr><td align="center" valign="middle"><a href="?<?=$next?>"><img src="<?=$files[$r_index]?>" /></a></td></tr> </table> </body> </html>
3 Responses
Leave a Reply
My name is Joey Nelson. I'm a web developer living in Raleigh, NC. I'm married to an awesome lady and we have an awesome one year old son. If you'd like to find out more about my fascinating life, check this stuff out:
Track me
Visit my sites
Other stuff
Latest posts
- Google ASCII Art Easter Egg
- Is it so crazy that someone would play VATFUL?
- Now that’s a quesadilla
- Automatically playing audio with HTML5 and Javascript (even on the iPad)
- Prevent console.log() errors
- Tumblin’
- omgtru updates and iPhone web app lessons learned
- Really?
- Easy form hints: HTML5 input placeholders
- Anthem Type
Categories
- apple
- art
- audio
- baseball
- bikes
- books
- browsers
- comedy
- complaints
- crime
- death
- dumb things
- energy
- environment
- family
- fonts
- food
- friends
- gadgets
- games
- henry
- html
- internet
- ipad
- iphone
- itunes
- javascript
- jquery
- life
- los angeles
- marriage
- movies
- msgblorb
- music
- mysql
- new york
- omgtru
- os x
- pasadena
- photos
- php
- plugins
- podcasting
- politics
- portland
- pugs
- rss
- ruby
- splideo
- subversion
- ubuntu
- Uncategorized
- video
- watir
- wordpress
- work
Does not work.
Can you give me some more information about what kind of system you’re running on and what kind of error message you get?
i am also having an issue getting this to work…
not sure what i am doing wrong…have index php in folder with two images named 0.jpg, and 1.jpg….in some browsers i get broken link in other nothing shows up…
this is it currently…
http://www.freevisualz.com/gallery/
thanks