EGallery – Automatic PHP Image Galleries

Delivering images to clients or models has always been a hassle, requiring me to either use another web service or asking clients to right click and save images from a list of files (how boring!). I was tired of explaining the difficult download process and wanted to come up with an easier method that is both simple for me and for clients downloading the images. That’s why I spent some time writing my own PHP script that will generate an image gallery automatically from any directory filled with images.

Presenting EGallery

EGallery (“E” for Eric) is a free PHP script that generates an image gallery automatically. Once you have a directory of image files, just upload the EGallery files to that same directory and “POW!” you have yourself a full-fledged image gallery. Thumbnails are automatically processed and cached and link to an original resolution copy of your images, which users are prompted to save to their computer. Want to see it in action? Follow this link for a demo.


Click on the button to the right to download Egallery.


Since EGallery does NOT use a database, the installation process is very easy. Follow these few basic steps to install EGallery on your PHP-enabled website in just seconds:
  1. Upload images to a new directory on your web server. For example: YOUR-WEBSITE.COM/sample/
  2. Upload the /egallery/ directory to the same subdirectory that you just created on step 1. Example: YOUR-WEBSITE.COM/sample/egallery/
  3. CHMOD the /egallery/cache/ directory as well as the contained index.html file to 777.
  4. Upload the index.php file included with the download package to the directory you created on step 1.
Once you have completed the step above, navigate to the image directory from step 1 using your web browser. The first time that you visit this page it may take a little while for the script to generate thumbnail files. After the initial load, those thumbnails will be cached resulting in a faster page load. You can configure this script by editing the /egallery/setttings.php file. This allows you to alter the <title> tag, change thumbnail image size, edit language elements, enable the image upload functionality, and turn on and off features.  


Q. Why don’t I see thumbnails? A. First, make sure that you have the correct write permissions. Set the CHMOD value to 777 for the cache directory and the index.html file within it. Another possible cause may be that the images are so large that they are using up your server’s memory. You may have to temporarily change your php.ini file settings to increase the memory limit. If you can get it as high as 128MB then you should be good to go. You can also try changing the MEMORY_LIMIT value in the thumb.php file. Q. The image upload page shows a success message, but why don’t I don’t see new files? A. If your image gallery directory (where the images are stored) is not set to CHMOD 777, then the upload script won’t have permissions to write the uploaded images to that folder. Change the permissions to CHMOD 777 for the gallery folder and then try re-uploading the images. Q. I set the permissions, so why can’t I still see thumbnail images? A. View the page source code to get the the URL for the image thumbnail, then navigate to that URL. If you see an error like “Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes)…”, then continue reading. You will see an error like this when your server is not able to allocate enough memory to process the thumbnail images. If you are able to edit your server’s memory limit, you should try adjusting it from the php.ini file (Google for more info). From Cpanel’s WHM page you can edit the memory_limit from the PHP Configuration Editor page. My suggestion is to temporarily increase the limit to a high number, like 128M, then reset it to normal after you have generated thumbnails. Q. I changed the password, but now I can’t login! A. If you were previously logged with another password the script has trouble overwriting the previous password cookie. Clear your browser cookies, then try logging in again.


  • Version 1.0
    • Initial release
  • Version 1.1
    • Added Upload feature(visit /egallery/upload.php)
    • Added Download all files as .zip feature
    • Misc bug fixes and updates
  • Version 1.2
    • Altered the style
    • Added option to display image EXIF details


7 Comments. Leave new

This is fantastic stuff, just as I was looking for a mobileme galleries replacement.

A nice feature to add would be that the complete EGallery could be independent of the images directories, and pass in the photo directories with a var. So that you only need one instance of the EGallery package, and can use an infinite number of image directories, without the need to copy in all the php files into each photo directory.
i.e. I could send a link to my mom
and a link to my boss
Both use the same php files, but are linked to different jpg directories.
not sure if my explanation makes sence…

but very cool script nonetheless.

Pete: I almost did that with EGallery. The first version that I wrote used central files and referenced them from multiple image directories. I decided to not continue with that method because I think that it makes the installation process a little less drag-and-drop simple. Someone without any web management experience can get the idea of uploading files then accessing it, but the more steps that I throw in the higher the chances of them getting confused and missing something.

The major benefit of having one centralized area for the EGallery files is that the upgrade process becomes a lot easier. Rather than uploading all of the files to every EGallery directory, you would only have to overwrite files in one spot. For that reason I might consider adding this feature in at a later time if lots of people start using EGallery.

ah, I see.
I hadn’t tought of that. So indeed there is a downside.

Thanks for explaining.


how do i change the size of images, the uploadzise one. thanks for amazing job!

Would it be possible to display images in subfolders?

Eric Heikkinen
November 1, 2013 11:27 am

I’m not sure if I understood your question, but I suspect that you it would be possible to create a centralized copy of the egallery core files so that you don’t need to re-upload them for every gallery. Here’s my guess at how you could do that, but be warned that I haven’t tested this out.

Domain structure:

  • domain.tld/egallery/ (containing the /cache and /js directories and egallery files)
  • domain.tld/folder-1/ (copy of index.php + Image files)
  • domain.tld/folder-2/ (copy of index.php + Image files)
  • domain.tld/folder-3/ (copy of index.php + Image files)

You would need to alter line 9 of the index.php file used in the image folders so that it points to the egallery source files. Here is what that section looks like:

// Customize this next line if you changed the location of egallery.
include_once "../egallery/functions.php";

Cool scrip Eric, thank you for sharing

I am getting the error “Warning: filesize(): stat failed for /domain/subdomin/…../index.php on line 64” so all images show as 0.00 KB

A nice feature for me would be the ability to show the images full size rather than just download

Thanks again

You must be logged in to post a comment.