Viewing your Photos

At home I use Googles Picasa for organising and viewing my photos on my day to day laptop. After downloading a batch of new ones from my phone, its a great way of deleting the ones you dont want, sorting the rest and browsing them all when you want to revisit those old memories. Afterwards I always upload or sync them with the photos folder set up on my server. Thats great for keeping backups (along with offsite S3 backups), but the only convenient way to view them is on the laptop, which is not always running. What about viewing the copies saved on the server, and on my phone rather than the laptop?

You could go the very straight forward route and save your photos to a directory in your web root folder, i.e. /var/www/html/mypics, and browse to them with your web browser, but that leads to three immediate problems. Firstly, Apaches directory navigation pages isnt a very attractive look or format for navigating through your folders. If you have properly secured your Apache server though, they may not appear.

Secondly, when you click on a photo to open it, you are downloading the full size photo over the network, as opposed to a smaller size thumbnail. Many photos, taken on a high resolution phone camera, can easily weigh in at over 1 or 2Mb or more. Finally, having your photos under the web root directory is a security concern. It is a risky location to save valuable items such as irreplaceable pictures as it opens them up to the potential of a web based attack, however unlikely that may be on your home network.

SINGLE FILE PHP

What we are looking for is a relatively safe and secure way of browsing the photos stored locally on our server from a web browser. There are a multitude of options out there, and it may indeed take some trial and error to find one that provides the right level of features you are looking for. What I was looking for in this immediate task, was simply a way to view the pics. There are many options such as Gallery3, Piwigo, Coppermine, etc, but the one I found very quick success with was a simple app called Single File PHP Gallery (mirror). Move to the directory you want to view your photos in, download the file and unzip it.

cd /var/www/html/photos
wget https://sye.dk/sfpg/Single_File_PHP_Gallery_4.7.0.zip
unzip Single_File_PHP_Gallery_4.7.0.zip

This will extract two files from the zip, index.php and readme.txt.

At this stage if you try browse to your [server_ip]/mypics folder, you will see a message saying that you need to set a Security Phrase. From your SSH session, use nano to open the index.php file

nano index.php

The config lines to take note of are the first three: GALLERY_ROOT, DATA_ROOT and SECURITY_PHRASE. Gallery Root is the directory containing your photos. Enter the directory path and ensure you leave a ‘/’ at the end of the path. NOTE: please ensure that your web server user, typically www-data, has Read access to the directory containing your photos.

Data Root is the folder where thumbnails and other data is stored. By default this is set to ‘_sfpg_data’, within this same directory, i.e. mypics/_sfpg_data, so be sure to create this directory. You can of course use a different directory and just update this setting.

mkdir _sfpg_data

Security Phrase is a phrase which the php file uses when displaying pages. The readme.txt describes this as a means of making the URL tamper resistant to avoid malicious use. Set it to anything you want.

Other options include PASSWORD, which will prompt you for a password when you browse to the mypics folder before you can view your photos, and ADMIN, set to FALSE by default. If this is changed to TRUE, it adds an Admin button to the display, allowing you to do extra tasks such as Delete, Rename, Move or Upload pics, and Create New Directories.

VIEWING PHOTOS

To view your photos, all you need to do is simply point your web browser to the directory and you get a very nice display of your photos. One thing to bear in mind, is that this PHP gallery script will show you the photos that exist as they are. That means if they are turned on their side in the folder, thats how they will be presented. It doesnt have the ability to rotate or do any manipulations of them. For that you would need to use a more capable photo browser. This is something I will be coming back to in time, but for now, this is a very nice solution that will allow you to browse your own photos on your phone at night from the comfort of your own bed.