Demo Anything you add is only visible in your own browser, and is cleared after 24 hours.

Keepsake

From an assignment to an album

Then & now

Keepsake started in August 2018 as my final marked assignment for a university module on building web applications with PHP and MySQL. The brief: upload a photo with a title and a description, check it really is a photo, resize it without squashing it, and show what’s been uploaded. In 2026 I brought it back as a proper photo album.

2018

Welcome to Ryan's pic upload service!

lets link to these images

woods
trees in winter
London
by night

Upload your photo.

Choose File No file chosen

Title for Image:

upload

One page, JPEG only, every photo at 150 pixels.

2026
  • Albums on a shelf, opened like a book, with pages that turn
  • A wall view and a full-screen viewer (keys and swipes work)
  • Six backdrops: Classic, Nature, Ocean, Love, Sunset, Cosy night
  • A live preview of the print while you type its title
  • JPEG, PNG, WebP and GIF, and iPhone HEIC where the browser can read it
  • Phone photos the right way up, with their hidden location data removed
  • Safe to leave open to the public: your additions are only shown to you

What was fixed

Looking back at the code was humbling. These are the things I’d now fail a student for:

The database trusted whatever was typed

The title and description went straight into the SQL. A title with an apostrophe broke the upload, and a carefully written one could have changed the query (SQL injection):

$sql = "INSERT INTO photogallery (filename,image,title,description,width,height)
        VALUES ('$resizedImg','$image','$title','$description', '$width', '$height')";

Now every value is sent separately from the query, as a placeholder:

db()->prepare('INSERT INTO photos (album_id, title, caption, file, …) VALUES (?, ?, ?, ?, …)')
    ->execute([$album['id'], $title, $caption, $saved['file'], …]);

Uploaded files kept the visitor’s file name

Photos were saved in the website’s own folder under the name they arrived with, so a second holiday.jpg replaced the first, and that name was printed into the page without escaping. Now each photo is drawn again from scratch, saved under a random name outside the website folder, and handed out by image.php, which checks who may see it.

Anyone could post from anywhere

There was no protection against another site submitting the form for you (CSRF), no limit on how often, and every visitor saw every upload. Now forms carry a secret token, uploads are rate limited, and in the public demo what you add is visible only in your browser and cleared after a day.

The page did its work in the wrong order

The upload was handled after the gallery had been printed, so you had to refresh to see your photo, and every visit tried to measure an upload that wasn’t there. Now a form posts, the photo is saved, and you are sent to the album with your photo in it (post, redirect, get).

What stayed

The idea, the title and description, plain PHP with no framework, and the database: it runs on SQLite by default and on MySQL with one setting (the MySQL tables are in sql/schema.mysql.sql). Even the resizing maths survived. In 2018 it was twenty lines of if statements; now it is fit_within(), which does the same job: keep the shape, never enlarge.

The photos in the starter albums are placeholders: illustrations painted in code for this demo, and run through the same upload code as yours. The 2018 code is kept alongside the new version for comparison.