August 3, 2007
Super simple PHP gallery
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>
2 Responses
Leave a Reply
My name is Joey Nelson. I'm a web developer living in Portland, OR. I'm married to an awesome lady and we have two weird little pugs. I do a weekly comedy podcast and make dumb songs with this guy Ben. I don't post to this blog very often, and very few people actually read it. If you'd like to find out more about my fascinating life, check this stuff out:
Stuff
Visit my sites
Visit my friends
Latest posts
Categories
- art
- audio
- baseball
- bikes
- books
- browsers
- complaints
- crime
- death
- dumb things
- energy
- environment
- family
- friends
- gadgets
- internet
- life
- los angeles
- marriage
- movies
- music
- mysql
- new york
- os x
- pasadena
- photos
- php
- plugins
- podcasting
- politics
- portland
- pugs
- rss
- ruby
- splideo
- subversion
- ubuntu
- 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?