Single File PHP Gallery 4.5.6

by Kenny Svalgaard


Single File PHP Gallery is a web gallery in one single PHP file. All you have to do is copy the script to any directory containing images to make a gallery. Sub directories will be sub galleries. Thumbnails for images and directories are generated automatically.
Single File PHP Gallery does not require any configuration or programming skills to use.

By default it looks like this:

sfpg    sfpg    sfpg
(click image to see the online demo)


  • Free for private non commercial use
  • Very simple Plug'n'Play like ease of use
  • Uses no Database
  • Automatically creates thumbnails
  • Slideshow option
  • PayPal integration with inventory counter for simple selling
  • Displays EXIF and IPTC information
  • Option to password protect gallery
  • Option to delete directories, images and files
  • Rotates images using EXIF information
  • 3D MPO red/cyan anaglyph and stereo image generation
  • Keyboard navigation
  • Option to create and use intermediate preview images
  • Option to add watermark to all images in gallery
  • Supports JPG, JPEG, PNG and GIF
  • Unlimited numbers of sub galleries
  • See configuration information for all features


For private non commercial use Single File PHP Gallery can be used for free. When used commercially a donation for at least 10$ must be made per domain where it is used. See readme.txt for full EULA.

You are of course still more than welcome to donate if you like the gallery, even though you only use it privately.

Making a donation:
Domain name must be clearly stated in the donation, otherwise the donation will not grant use of the script under donating conditions. Donations are not refundable.
Use the following PayPal donate button for donations:


For this gallery to function you will need the following:
  • A web server capable of running PHP 5 scripts
  • The PHP GD library (php_gd) installed. See here for information:
  • PHP write access to server
  • PHP memory limit large enough to contain both full size image and preview/thumb (converted to BMP) See the FAQ section in readme.txt for further information on this.


Download latest version here: Single File PHP Gallery 4.5.6 (34kB)
Download SFPG TEST script here: SFPG TEST 1.1.4(26-March-2015)

NEWS IN SFPG 4.5.6 (15-December-2014)

    Versions of Single File PHP Gallery below 4.5.6 could allow specially crafted code embedded in images (in EXIF or IPTC) or in description files, to reach end users browser for execution. All users of the gallery, having or allowing images and/or description files from untrusted sources, should upgrade to this version to keep end users safe from this risk.
  • Improved security by adding HTML encoding of data sent to clients. See ALLOW_DESC_HTML option for information on how to enable HTML in descriptions.
  • Removed the NL_TO_BR option (line breaks in description files will now always be shown).
  • Upgrading from a previous version of the script requires the contents of the DATA_ROOT to be deleted.

NEWS FROM SFPG 4.5.5 (13-December-2014)

  • Added image area navigation. Clicking the left third of the image area when showing an image will go to previous image. The right third will go to the next image. Clicking the image in the middel third of the image will close the image. Related buttons in bottom menu light up when hovering these areas. The middle third of the image area can also be used to zoom and/or move the image around when watching a large image in actual size on a touch device.
  • Added automatic recreation of data files, including thumbs and information, when images in GALLERY_ROOT are changed.
  • Added option to have a banner/header shown in the gallery. Can be used as a standard banner on all pages or individual per directory. See TEXT_BANNER and DIR_BANNER_FILE for information.
  • Moved the TEXT_CLOSE_IMG_VIEW button.
  • Fixed handling of backslashes in input like EXIF, IPTC and description files.
  • Fixed SHOW_IMAGE_DAYS not working correctly when not sorting by date in reverse order.
  • Fixed $color_img_hover, $color_img_hover_text, $color_file_hover and $color_file_hover_text not being used.

NEWS FROM SFPG 4.5.0 (25-November-2014)

  • Added option to password protect the gallery. See the PASSWORD option for details.
  • Added option to enable delete functionality. Directories, images and files can be marked and deleted from within the gallery. See the ADMIN option for details.
  • Added option to sort images by date/time from EXIF aka when the image was take. See the IMAGE_EXIF_TIME option for details.
  • Added function to allow file-preview images to be used for gallery thumbnails.
  • Improved the option to use images as thumbs for files by extension. Setting $file_ext_thumbs is no longer needed, so the $file_ext_thumbs setting have been removed. See the ICONS_DIR option for details.
  • Changed constant name SORT_NATURAL to SORT_ALL_NATURAL because SORT_NATURAL is already defined by PHP.
  • Changed constant name DIR_IMAGE_FILE to DIR_THUMB_FILE because it is a more saying name. Also changed the default setting from '_image.jpg' to '_dir.jpg'.
  • Changed the DATE_FORMAT parameters.
  • Changing the DATE_FORMAT no longer require rebuild of DATA_ROOT to apply.
  • Upgrading from a previous version of the script requires the contents of the DATA_ROOT to be deleted.

NEWS FROM SFPG 4.4.0 (31-October-2014)

  • Added 3D MPO image extraction, with red/cyan Anaglyph image and stereo image generation options.
  • Added option to set or disable the round corners on boxes.
  • Fixed "Empty regular expression" warning from showing on some servers.

NEWS FROM SFPG 4.3.0 (2-October-2014)

  • Added option to enable slideshow.
  • Added option to only show a set number of images.
  • Added option to hide images older than a set number of days.
  • Added option to delete images older than a set number of days.
  • Added automatic clean-up function to have the gallery delete unused files in DATA_ROOT.
  • Added option to enable simple PayPal integration with inventory counter for selling.
  • Added option to show directory description inside the gallery using a new wider "thumb-box".
  • Added option to change the icons/watermark directory.
  • Added option to set an image to be used as thumb on all directories not containing images.
  • Added option to have the watermark scaled to a constant fraction of the full size image.
  • Added disabling of image navigation (buttons and keyboard), while loading image.
  • Improved disk performance by adding check of name and/or description files before trying to load them.
  • Improved JavaScript function to show full size image faster.
  • Improved full size image load to avoid fading in the previous image.
  • Fixed choosing of thumb for directories. Was an issue when using SORT_NATURAL, which is default.
  • Fixed handling of files and directories called "0" (zero).
  • Fixed so that information box does not close when using ESC to go one directory up.

See here for changes in previous versions: Single File PHP Gallery Version History


Subscribe here to be notified via e-mail when a new version is released: eMail Notification

CONTACT / SUPPORT (English or Danish/Dansk)

Please use the link below if you have any comments, questions, requests, greetings etc.

If you are having problems getting the script to work, then please download the SFPG TEST script from the DOWNLOAD section above, and paste the output from it into the message, along with a description of the issue you are having.
Use the contact form on this page: Contact