Shampoo: a simple PHP photo gallery

Shampoo is a very simple photo gallery script that doesn't require a database.

Shampoo screenshot Main page, showing all albums

The gallery is built using the existing directory structure, where thumnails are created and stored by the script.

The HTML produced is minimalistic, semantic and template-based.

Unobtrusive JavaScript is used for progressive enhancement and can be removed entirely with no loss of functionality.

You can add captions and album descriptions using a very simple text file.

For a demo, visit my photo gallery.

» Download (54kB) Contents of the archive

Requirements

Your server needs to run PHP 5+ and it must understand .htaccess files because mod_rewrite is used to make nice URIs. This is pretty standard and the vast majority of commercial web hosts will have no problem with this.

In order for thumbnail creation to work, your server will also need to have GD installed. Again, any host worth its salt will have GD installed.

Instructions

Shampoo screenshot Single album view

  1. Extract the archive (shampoo.zip) into a directory on your server.
  2. Make new albums by making new directories under the one where you extracted everything.
  3. If you want captions for the pictures, open up index.txt and follow the instructions there.
  4. That's pretty much it. To see it, simply point your browser to the directory (index.php is the thing to run). For example, if you've put the gallery in the root of your domain, just go to http://www.mydomain.com/shampoo/ (or whatever you called the directory).

License

BSD-style license. This means you can pretty much do whatever you want as long as you give due credit.

Problems?

If you have trouble viewing individual albums or images, it is most likely a problem with mod_rewrite and your .htaccess file (in the base directory of Shampoo).

  1. Check that mod_rewrite is enabled on your server. This can be achieved via phpinfo or by asking your host.
  2. Open .htaccess in your text editor. Below are four alternate blocks of text that may work for your setup. Try each one in succession by replacing the entire contents of the .htaccess file with it.

Shampoo screenshot Single image view

RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?[^/]+$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?[^/]+/\d+$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^/?[^/]+/thumbs(/.*)?$
RewriteRule ^/?(.+)$ index.php?fish=$1 [L]
    
Options -Indexes
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?[^/]+$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?[^/]+/\d+$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^/?[^/]+/thumbs(/.*)?$
RewriteRule ^/?(.+)$ index.php?fish=$1 [L]
    
Options -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?[^/]+$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?[^/]+/\d+$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^/?[^/]+/thumbs(/.*)?$
RewriteRule ^/?(.+)$ index.php?fish=$1 [L]
    
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?[^/]+$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?[^/]+/\d+$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^/?[^/]+/thumbs(/.*)?$
RewriteRule ^/?(.+)$ index.php?fish=$1 [PT]
    

mod_rewrite is the most likely issue, especially if you are using a subdomain or if you know you are using mod_alias. If your filesystem is very different to the URI structure, then it is also likely you will need to use a RewriteBase directive.

The single / is most commonly needed when RewriteBase is required, but some hosts (e.g. 1and1) might require the path too. For example, if your base directory is called "pictures":

RewriteBase /pictures

If your host supports PHP 4 and PHP 5, but it defaults to PHP4, you need to add this right at the top of your .htaccess:

AddType x-mapp-php5 .php

If any of these turn out they work out for you, I'd like to hear about it.

Contact

If the steps above didn't help, if you encounter bugs or if you have any other questions, email me:

r [at] this domain

Comments

Post a comment (Optional)
  • Allowed markup: <a> <i> <b> <em> <u> <s> <strong> <code> <pre> <p>
  • All other tags will be stripped, unless they are in a <pre> (use this for blocks of code)
  • External links will have the rel="nofollow" attribute applied