Easy PHP Photo Gallery

March 19, 2007

Topics: Accessibility.

I dropped support for this project in about 2012, and the files are no longer available for download. Thanks for stopping by!

There are a lot of PHP (Hypertext PreProcessing) photo gallery scripts out there. I know; because I went looking for one some time ago, and found myself barraged with Javascript, AJAX, and complicated installations. I didn’t want any of those things, so in the end I just wrote one for myself — and this is the end result. Download the ZIP package.

It’s not a complicated script, and it doesn’t do a whole lot for you: but, assuming you’re running on Linux with PHP, it’ll be incredibly easy for you to install and configure. View the sample installation.

What’s in the Package?

There are six main files included in this zip package (Version 1.2):

  1. gallery.php — the photo gallery script. Now contained in functions.php.
  2. index.php — the home file which includes the gallery script and contains configuration info.Configuration now in separate file; gallery files now contain only a few gallery-specific variables. You can copy this page to create additional galleries just by saving it with a new name and changing the configuration information. test.php is a second example referencing a separate gallery, to demonstrate the multiple gallery features.
  3. titles.txt — a simple text file which uses pipe-separated fields to indicate the image name, an image description, and an alt text option.
  4. title.php — a script which provides a unique title element for each image in the gallery. Now contained in functions.php.
  5. basic_styles.css — a very basic stylesheet so that your default photo gallery doesn’t look too boring. Warning: no attempt whatsoever has been made to test these styles outside of Firefox.
  6. readme.txt — installation instructions

I’ve also supplied a (very) small gallery of images for the included gallery.

What does the script do?

This is pretty straightforward. The configuration information you’ll send to the script provides the title of the gallery, the relative path to your images folder, and the name of your text file containing the image information. Using this information, the gallery script creates a page containing (in order):

  1. Navigation links to move between the previous and next images in the gallery. The sequence is the order in which you’ve listed the images in your text file. The navigation is circular, so in the initial position the previous link will send you to the last image in the gallery.
  2. A full size image with a caption. The caption is the second field in your text file.
  3. An unordered list of thumbnail images in the gallery. Again, the order is from the text file. In the default styling, the list is displayed as a panel of images rather than as a list. Each image is a link to the full sized image within the gallery.

The script does NOT automatically generate your thumbnail images. Sure, I could have done that — but my feeling is that manually creating thumbnail images will usually be more aesthetically pleasing. My preference is to create 80×80 square thumbnails cropped from the image. The tiling effect of the unordered list is much more effective with square thumbnails; and the ability to choose a particular section of the image for the thumbnail is much nicer than whatever programmatically selected truncation might have done.

Some Small Recommendations

The script allows the ability to use an alt text on your images. It also provides a description which can be used to caption the images in a paragraph either over or under the image. To me, it’s redundant to provide both descriptive text associated with the image AND a descriptive alt attribute. Therefore, I’ve also provided the option to turn off alt text in the full sized images. The default settings are what I’d recommend: visible descriptions enabled for the full size image, alt attributes left blank, and alt attributes enabled for all thumbnails.

I also recommend keeping your alt attributes short and to the point. The reason for having separate descriptions and alt attributes is because they serve different purposes: don’t try and use the description field as an alt attribute and don’t try and use the alt field for a description!

There’s nothing fancy about this script. Really — I mean it. It’s down and dirty “make me a photo gallery” programming. Use at your own risk!

Changes as of 2/6/2010

  • Improved pagination feature, adding a control to set the number of visible page links at a time.
  • Simplified support for multiple galleries.
  • Generate a list of available photo galleries.
  • Navigate through multiple galleries continuously.
  • Separated most configuration options into an external file, rather than configuring the same options for every gallery.

These changes are very substantial to the core code; although the majority of the actual code has remained the same, the structure of the code usage has been significantly revised. See the readme.txt for details on usage.

On the whole, this should be easier than ever before; although you may be in for a little work if you’re trying to revise.

Note: The basic output (HTML (HyperText Markup Language), unique ID’s, classes, etc.) is unchanged. The format of the titles.txt file is unchanged. The only changes are in the addition of new features, in the way configuration options are set up, and in the way information is output from the scripts.

171 Comments on “Easy PHP Photo Gallery”

  1. Hi Joe,

    It is a long time ago since i asked a question about the photo gallery. The previous version is still in use and almost completely rebuild. But i have one question about the page ‘loop’ previous – next. when navigate trough the pages you start for example by pictue 1 and finisch by 30 but when you press next again, you’re back at the beginning. Now is my question, which part of code do i need to change for simply start by 1 and end by (for example )30?

    Greetings, Mark (Netherlands)

  2. @David I can’t speak to the PHP (Hypertext PreProcessing) portion; but the output is a jQuery gallery plugin called ColorBox.

  3. I’m stumpted. I have a php gallery on my website, webmaster made it for me a year or so ago, he’s gone and the new webmaster can’t find the php gallery code as the original is embedded within some big overall php set up, or something.

    Anyway you could, after seeing the gallery page on my site (click the gallery link) that you could ascertain which php gallery it is and send me the coding for it? It’s close to the one you have on this webpage.


  4. Joe, Greetings Sir and thank you.
    Every time I try to make one step forwards I seem to go two steps backwards.
    When I started my project I didn’t have a clue with programming.
    Your Gallery inspired me and after countless library books and ‘Google’ searches am getting far more proficient.
    However, there will come a day when I will need to hire your incredible skills.
    Currently I am still learning to understand the questions, let alone have the answers.
    The past several days I have been learning Javascript (have used it in other areas of my project) and can now currently have one image frame within cycles a set of images. This is to be the introductory page to my website.
    Within the site I will use your Gallery, as it was designed, to be used in a static mode.
    Love it, so neat and stylish.
    Joe, the objective I have is for ANYONE to be able to send me a picture and for my own email system to interrogate the image and reduce its size to 2400 x 1800 and convert from whatever format the camera image was taken into a JPG format.
    The sort of tasks you would do in Photoshop I am trying to do dynamically yet transparently to the sender. (Plus far more)
    Most of this I can now do.
    Hence currently please do not take any action on my request.
    Mind you I will have a try at getting Javascript to work within your Gallery when I get a chance and actually one gallery would be sufficient.

    Thanking you yet again, your support is incredibly appreciated.

  5. @Philip Making the thumbnails automatically cycle would be a JavaScript addition; my goal with this gallery is to make things pretty minimal, but I’d bet that something could be added to the script which would be able to do that under certain conditions. It would be worth looking into, at any rate! Thanks!

  6. Joe greetings. Please delete the messages from 10 Sept.
    The ini file suggestion ridiculous and portrait mode resolved anyway.

    Joe is there any chance of making the thumbnails a changing collage
    say automatically skip to the next after an adjustable period of time?’

    Perhaps even cycle to the next gallery?.
    That would be awesome.
    Oh and Joe inspired by your work I have learned so much re CSS (Cascading Style Sheets) etc etc.

    Thank you.

  7. Joe, hi again. I have been trying to use portrait pics
    in a gallery and found the scaling down to be a bit erratic.
    Not staying at a constant 460×600.

  8. Joe would it be possible to use a flat text ini file to add a new gallery.
    To make it very simple and quick to add a new small gallery.
    When you are happy with the general appearance it should be possible
    for basic additions in a few moments.

  9. Joe………………………….
    Incredibly impressed. Quite Awesome.
    Much easier to install than 1.2.
    LOVED you adding thumbnails.
    Extremely elegant code, well done Sir.

    However may I make two comments, constructive not critical.
    a)In basic_styles.css Made change #wrap {width: 640px; text-align: center; margin: 0 auto;}
    from #wrap {width: 620px; text-align: center; margin: 0 auto;}
    On different pc’s here the thumbnails overlapped the main image.
    Actually it did this also with 1.2 and I remembered my fix then.

    b)”Skip to thumbnails” does not seem to work.

    Overall opinion :- huge congratulations.

  10. Yeah, you’re right – I always have to reference the manual to doublecheck which is which. I’m guessing you didn’t alter the sort on both the full size image array and the thumbs array? There are two arrays: $image[] and $photo[], both of which you’ll need to adjust.

  11. Thx for the tip, but afaik it will change the key index as well? arsort() or krsort() seems like a better solution. I was able to revert the array with krsort() but somehow everything else stayed in the same order..

    Atm I got everything sorted already except for the thumbnails; last image as full pic and non-circular next/prev links.

    Just reverting it for the thumbnails would be ideal but I didn’t get that to work yet..

  12. I think that what I’d do is probably just reverse sort the array of images when they’re read from the file originally. I haven’t looked at what this would take, specifically, but it seems like using rsort() to change the order of the array would be useful, rather than recoding the logic.

  13. Hey Joe, Yeah I’d like to let the gallery run backwards so that the last image added to the .txt file will be displayed first (in the thumbnails as well).

    I managed to display the last image (full) after all when a is not set with;

    $lastImage = end($image);
    $display = $lastImage[0];
    $description = $lastImage[1];
    $alt = $lastImage[2];

    + a minor change to the previous button when a is not set, by declaring; ‘$suma = ($suma – 1);’

    But the thumbnails themselves prove to be a bit harder. I reckon it has something to do with the $start and $finish variables but not entirely sure?

  14. I just saw your sample installation and there are good. You love animals? I really like your gallery. I am also an animal lover.

  15. Do you mean that you want the pictures gallery to essentially run backwards, or do you mean that you’d want to start with the last image, but then continue around in a circular fashion?

  16. Hi there, great simple script! Very easy to use, although a bit messy ;P

    I wondered if it’s possible to let a gallery start (big + thumbnails) with the last pic added to the .txt file. I tried to fiddle around to get the last item in the array but can only get the array nmbr and not the actual img value. Prob my lack of php coding skills.

    Would you know of a solution? That would be greatly appreciated!

  17. OMG, Joe, you are an incredibly generous man. Not only do you provide an excellent script, you seem to also provide in-depth troubleshooting. Kudos to you! I admire your patience.

  18. Hi!

    Nice piece of scripting. I use it my website. Is the skip to thumbnails link not really functioning?

  19. Hi, have just started using the script and I think it’s brilliant, but I have one problem. Is it possible when clicking on a thumbnail for the image and its description to appear in a popup window instead of next to the thumbnails? If so, what code do I need to change to make this happen?

    Thanks in advance, Steve.

  20. Okay, thanks I’ll see it then

    greetings, Mark

  21. Hi, Mark – I’ll try and find time to come up with a solution for you in January. Basically, you need to add a function to the script which organizes the galleries into groups, and indicates what order the galleries should sequence in, then automatically passes onto the next gallery when it reaches the end of the previous. It’s not, on the whole, a complicated change, but it’s not trivial.

  22. Anyone who knows a solution?


    Combine different directories in one sitemappage were from each page plus minus 5 photo’s are shown for example:

    http://www.fotologboek.nl/fotografie/natuur.php (30 photo’s)
    http://www.fotologboek.nl/fotografie/paddestoelen.php (32 photo’s)

    Problem, each page has is own .txt wich uses for text by PHP (Hypertext PreProcessing)

    Greetings, Mark

  23. Hi,

    Maybe this is a little bit clearer, I’ve updated my website to Fotologboek.nl v1.1

    http://www.fotologboek.nl – See the navigation below ‘Fotografie’ (Photography)…

    Maybe I’m using you’re script in a to large context, because it’s nog a single part of a website with a couple of photo’s. So there are several photomaps.

    Greetings, Mark (Netherlands)

  24. Hi, Joe

    The reason is that I want to make a summary page, where al de photo’s from different maps: Nature, Weather, Sports come together.

    When I navigate the photoloop starts by the beginning when clicking on the next button from the last picture. But in this case I want to connect the pages with eachother

    each photopage has his own map:

    Nature.php / Nature + text.txt
    Weahter.php / Weather + text.txt etc.

    Putting al the images in one map create a mess, because it will grow to hundreds.

    Greetings, Mark

  25. Hi, Mark –

    Sorry about the delay, but I’ve been pressed by work commitments. 1) Yes, it would be possible, but would require some fairly significant changes to the template. Not terribly difficult, on the whole, however. 2) I’m not certain what you mean. An image map is an image which has various “hot spots” defined as links within the image using HTML (HyperText Markup Language). I don’t see how that even relates to the photo gallery…can you explain what you mean?

  26. Hi Joe,

    How do I use photos from several image maps in one page?

    for example:

    $map = “nature”, “sport”;

    Greetings, Mark

  27. Hi Joe,

    I have two new questions, When you see a page like Youtube you have an input field that shows the url from te movie.
    Is something like that possible by the “large” picture. The reason for this function is for other plans that are still on my checklist πŸ˜›

    Greetings, Mark

  28. Excellent. Glad that it worked out for you! πŸ™‚

  29. Joe, Sir.
    Your suggestion worked perfectly.
    You are brilliant.
    Thank you so much.


  30. Joe I have no idea what happened in the above. I cut and pasted the comment and it was severely edited.

    Simply put, with all the changes installed, that you so kindly provided, the upgrade fails with the results being a blank screen as per :-

    If I leave out the to component from the gallery.php script, with all other supplied changes installed, it returns to the original working
    Obviously with the JAVA print feature not working as yet.

    Please can you make suggestions?.
    Thank you Joe and I hope I have clearly expressed the problem.

  31. Joe I am overwhelmed by your kindness. An incredible thank you.
    Sadly I can not get your changes to work.
    With all your changes installed when I start the program all I get is a blank but correctly colored blank screen.
    If I leave out the addition :-
    Place this in the gallery.php PHP (Hypertext PreProcessing) script, after line 96 and before line 97.
    Line 97 is “echo “n”;

    echo “n”;
    The program works normally again.

    In the html I tried adding:-

    var pwin;
    function printImg() {
    pwin = window.open(document.getElementById(“mainImg”).src,”_blank”);

    before <?php
    and within the end of php script

    also between ?> and

    It seems the problem is with the addition of :-

    into the gallery.php causes the failure (just a blank colored screen).

    Removing the addition and retaining the other additions the gallery worked as previously.
    You can see effects from http://www.price-solutions.com/basic/index.php
    and http://www.price-solutions.com/basic2/index.php

    Thanking you yet again and again,
    p.s. Joe you are correct re: not being over 100, but mother-in-law lives with us is 99, that is close.

  32. Hi,Joe. Thanks for your scripts. I downloaded it. and it work well with my web.

  33. Hi Joe,

    I’ve wondered if you have made/found some php in the meantime for the pagination within the gallery. Because with a growing amount of photo pages it could be very useful when the numbers would reduce to 5 per page for example.

    Greetings, Mark (Netherlands)

  34. Greetings Joe.
    What I am trying to do is to provide a gallery of images taken DURING a wedding ceremony.
    At the following reception each guest would be given as a gift a photo taken during the ceremony.
    The person taking the picture OR printing does not require technical knowledge.
    When the gallery is displayed ‘they’ chose the ‘nicest’ picture from the gallery.
    Please view the above URL (Uniform Resource Locator).
    Then a click on “Print this Photo’ PUTS the current image (is it located in $_GET[‘a]’ ??) into a directory such as \home\my_name\wedding_pics\

    Joe I have added/changed the text of ‘Previous’ to ‘Print this Photo’ as an example.
    I have NO idea how to do a PUT of $_GET[‘a’] into say \home\my_name\picture\
    PLEASE help is possible……
    (Oh and Joe I am likely older than your grandfather)
    My warmest appreciation

  35. Hi,

    I’ve send you an e-mail with the scripts as I used it. In the mean time I have tried different ways, but all ending with the same errors.

    Greetings, Mark

  36. There shouldn’t be any need for a separate text file. You just need to reference the same text file as you are for the gallery itself.

    I’m uncertain why you’re coming up with an undefined function error — but it’s very difficult to provide definite advice without actually seeing what you’ve done. Try including the counting script as the very first thing on the page; perhaps there’s an order of events problem.

  37. Another solution would be $results, but this doesn’t work outside the script the menu.php include…

  38. Hi,

    I tried it in different ways, but the call function give any time an error:

    Step 1

    Put the call tag echo numImages(“informatie”); (with php tags, offcourse) (but won’t show up in message) in the span tags from the menu.php

    step 2

    I put the script is a separate file counting.php and included it in the same page as gallery.php



    and then, nomatter what I tried (online and offline)

    Fatal error: Call to undefined function numImages() in C:\Program Files\EasyPHP5.3.0\www\invoegingen\fotobestand.php on line 6

    Last possibility, do I need to make and seperate textfile?

  39. The function can really go just about anywhere, as long as it doesn’t interrupt any of the other logic – at the beginning or the end of the script is fine. In fact, it could be a separate file entirely, since it’s completely independent of the gallery script itself.

  40. Hi,

    Okay, I have backups for mistakes I make, so that’s not the problem.
    Because I’m still a newby at PHP (Hypertext PreProcessing) I thought that the script you gave me was a replacement with extra functions, because in the script where tags that used in the existing script.

    But as I understand now, it is the intention that the script/fucntion is placed separately in the gallery script. The question that than remains is, where in the gallery script do I need to place it?

    And do you have also solution for the pagination?

    Greetings, Mark

  41. Hmmm. Well that could confuse things…I’m surprised that the script still works if you took out the original code and replaced it with the function I provided, even with your modifications. It was really intended to supplement the script, not replace anything.

    The problem with simply accessing the variable outside the script is that the variable is only defined within the context of the script. The function, however, is defined globally when the script is available. You can call the function during another script (or as an independent script) and have it operate effectively. However, it needs to know what gallery to operate on; which is why I provided the text document as an argument for the function. Without that argument, there’s no way to access the information for a specific gallery.

  42. hmmm, script doesn’t show up between can I e-mail this to you?

    I replaced this:

    $fp = fopen($tekstlijst, ‘r’);

    while ($buffer= fgets($fp,4096)) {

    $afbeelding[$y] = explode(“|”, $buffer);
    $foto[$y] = str_replace(“.”, “_tn.”, $afbeelding[$y][0]);
    $resulteert = count($foto);

    With this:

    function numImages($tekstlijst) {

    $file = getcwd() . “$tekstlijst”;
    $fp = fopen($tekstlijst, ‘r’);

    while ($buffer = fgets($fp, 4096)) {

    $afbeelding[$y] = explode(“|”, $buffer);
    $foto[$y] = str_replace(“.”, “_tn.”, $afbeelding[$y][0]);
    $aantal[$y] = $buffer;
    $resulteert = count($aantal); return $resulteert;

    With your counting script, I translated the strings in Dutch. When i used the string ‘resulteerd’ inside the gallery script, it showed the number of photos, but outside the gallery script, in another php file which also included in the same photopage I would’nt work…

  43. I replaced this:

    With this:

    With your counting script, I translated the strings in Dutch. When i used the string ‘resulteerd’ inside the gallery script, it showed the number of photos, but outside the gallery script, in another php file which also included in the same photopage I would’nt work…

  44. @Mark I’m not sure I understand what you’re saying. What did you use, and where?

    @Philip It is fairly easy to write a script which generates thumbnails; but doing that dynamically can be very costly of server resources. Better would be to use a script to upload your images which also generates a thumbnail version of the same image in the process. It would be more work than I’m likely to go to to actually incorporate that into the same script, however. The whole point of this script is that it doesn’t do a lot for you; just takes the images you give it and assembles them into a gallery.

  45. Hi Joe.
    Some time ago you mentioned it was be ‘fairly’ easy to have your
    script automatically generate the thumbnails.
    Have you considered this?.
    Perhaps similar size to current ones ( 80 x 80) but with a possible
    location set approximately 1/3rd from the top in the center?
    It would be a great help to me.

    Oh and your font size stability is far better than mine across
    different browsers.


  46. Hi,

    Maybe I’m getting this wrong, but I replaced the script you gave me with the existing part. Because in that script where the same functions.Or do I need to place this script beneath the existing one…

    Menu.php is included in the samen page as the gallery.php.

    Greetings, Mark

  47. Hi,

    Maybe I’m getting this wrong, but I replaced the script you gave me with the excisting part. Is this wrong, or is it an extra function that needs to be placed beneath the existing script?

    De menu.php is included in the page where also included gallery.php

    Greetings, Mark


  48. Hi, Philip – thanks for your comments, but none of those are actually a part of the script. The ability to right click on thumbnails and get the alternate text in properties is a browser feature. The alt attribute text is set in the script, but that doesn’t change anything about how you can access the text in the browser.

    Font sizes may well change in various browsers – the CSS (Cascading Style Sheets) delivered with the script is nothing more than an example layout, and not intended for use in a production setting. No effort has been taken to make it work identically across various browsers.

    There’s a possibility I’d actually release a version with some various CSS layouts available, but it’s not at all a top priority.

    @Mark You should be able to run the function as long as a document with the function included is also available on the page. It would just be a matter of including in the place you want the number to appear.

  49. Greetings Joe.
    Just to let you know. With your thumbnails for me a VERY
    important feature is :-
    >right click on thumbnails>properties>alternate text
    In my case the information would be supplied by a comment
    supplied when the taker of the picture downloads it from
    the camera and adds the text as a ‘comment’
    Feature works perfect with Firefox but does not work in IE (Internet Explorer) 7 and 8
    I have not been able to test with Apple yet
    My warmest regards
    p.s. fonts possibly change sizes in IE too..will confirm

  50. Oke, I’ll hope it is possible.

    I have in the mean time the problem with the photocounting script you gave me. When I’m adding a $string inside the gallery.php the counting works. But I don’t know how to add a string in another php file for example categories.php in this script is a span tag and thats the place where I want to add the string like an class by CSS (Cascading Style Sheets).


    php/fotoscript.php (gallery php with the script you gave)

    includes/categories.php (the menu with the span where I want to show the amount of photo’s)

    Greetings, Mark

  51. I’ve done that before, with a different script – I’ll look end see how easy it would be to incorporate the pagination method from my search script into this one. It shouldn’t be unmanageable.

  52. Hi,

    In the mean time I’m trying some things with the pagination. Because when I created al larger number of pages, the paginantion doesn’t stop…


    1,2,3,4,5,6,7,8,9,10 etc.

    should look like this

    .. 1 .. 5,6,7, … 10

    or this

    … 5,6,7,8,9 … next page … 6,7,8,9,10

    Greetings, Mark

  53. Hi,

    Thanks for the quick and helpful response. On the test page which has a part a html script from inside the gallery.php it works with a string. But the problem is now that the category navigation is a include php which is included in index.php for example, how do I implement the string in a included file form another path?

    Thanks, Mark

  54. Well, here’s a function which will do what I described:


    This is completely untested and written off the top of my head, so no guarantees – but it should get you started.


  55. Hi,

    My experience with PHP (Hypertext PreProcessing) is not that big, so can you give an example or a start? untill now I used extra strings to increase the functions for the photo that was a easy to make, like a date, description and name. After that I created a sequence in the textfile and it worked. With this I need to fill in a number in a file called ‘fotobestand.php’ between the tag…

    So if you can give me an example or a start, I can figure it out by my self, and learning from it πŸ™‚

    Greetings, Mark

  56. That’s a very nice implementation of the script! The photo count is available in the variable $result, but I suspect that’s not what you’re looking for. You’re looking for something where you can simply insert the number of images in the gallery into the category navigation, right?

    Well, the easiest thing would be to simply add a function to the script which runs the number of images – then you could call that function.

    You can just re-use the count code already in the script as a function, and call the function with the text file as an argument. Then you have a simple function which takes a file, counts the number of records in the file, and returns the value.

  57. Hi,

    The problem about the scriptstructure is solved, i’ve created a string an builded a list where i can fill in the information that I wanted to show.

    In the mean time I saw another script with a photocounting, is it possible to integrate something like that in this script?

    In de Category navigation I made a tag where I set the number of photos per category by hand. It would be much easier if it runs automatic per photocategory

    http://www.fotologboek.nl/fotobestand/paddestoelen.php >>> Category navigation at the left.

    Greetings, Mark (The Netherlands)

  58. Modifying the PHP (Hypertext PreProcessing) would be a significant chore. The way the script distinguishes between one gallery entry and the next is by splitting the information on line breaks — thus the problem when you place a hard return directly in the text file.

    If what you want is for your .txt file to look clean, then there’s nothing I can really do to help you. If what you want is for your output source to look clean, I’d suggest trying the /n character to create line breaks in the output.

  59. Hi, Problem with thumbnailnav solved!

    Another question, why is it impossible to use ‘enters’ in the .txt file for photo descriptions. Reason for that, I want to integrate a small table for each photo which contains information about de camera/photo specifications. Because of the errors that appear when I use enters I need to put al the HTML (HyperText Markup Language) on 1 line. An whit a table en a short photo descriptions the scriptstructure turns into a mess…

    Is there another solution for this problem? Or can I modify something in the PHP (Hypertext PreProcessing)?

    Greetings, Mark

  60. Hi,

    Why is there a linebreak after alt=”” in the tag? Is this because of the .txt file? I’m cleaning up my scriptstructures and found this problem.


    Greetings, Mark

  61. Hi joe, is there any way I can mod this to just output all the files in the specified without having to include the text file?

  62. Well, you can always mess around with the math to switch it from a starting count of 1. It’s just set up to use a basic decimal counting system. It’s not something I’m interested in messing around with, though. I’m not certain off the top of my head (I wrote that loop a long time ago,) but I think the change would require quite a few small changes to the code.

  63. Hi,

    The script is now full in use, and the last few days I’m implementing the PHP (Hypertext PreProcessing) and CSS (Cascading Style Sheets) to make my own layout.
    I’d noticed that when I click on a thumbnail, for example “thumbnail 1” the link: http://www.fotologboek.nl/?a=0 will open, and not http://www.fotologboek.nl/?a=1 … Is it possible to fix this? So when i click on the first thumnail this link will open: http://www.fotologboek.nl/?a=1 instead of http://www.fotologboek.nl/?a=0?

    Greetings, Mark

  64. You can include HTML (HyperText Markup Language) in your .txt file, but using an HTML file in place of the .txt file would get much more complicated. In the .txt file, where the code calls for the description, just add the needed HTML to your text string.

  65. Hello,

    I had one questions that not has been answered yet: Is it possible to use a HTML (HyperText Markup Language) file instead of an txt. file to show descriptions/titles beneath the pictures. If so, what do I need to change?

    I’m a newby in PHP (Hypertext PreProcessing), but I’m willing to learn

    Greetings, Mark ( The Netherlands )

  66. Greetings Philip

    The CSS (Cascading Style Sheets) and the page self are not completed jet, and I’m rebuilding the CSS to give it another sytle like my other site Weerlogboek.nl. I’m editting the scripts and use my knowledge about HTML (HyperText Markup Language) and CSS. For now it’s just a testpage/beta page.

    My other site, Weerlogboek.nl has a finished CSS and HTML, so if you’re interested in the CSS, you can look there.

    Greetings, Mark (Sorry for my bad englisch)

  67. Greetings Mark.
    I REALLY like and admire the aesthetic look of your gallery.
    However I have little knowledge of CSS (Cascading Style Sheets), so learning.
    Does the basic_styles.css provided by you have entries not used within
    your gallery? I.E. a generic CSS used by you elsewhere?
    The reason is that I have written a program to receive images via a
    single form combining an email and POST.
    This will be the source of the images within gallery.
    I would like to make my work compliment your style/CSS.
    Thank you

  68. That should be something readily adjustable using CSS (Cascading Style Sheets). You’ll need to adjust the width of the #thumbs div, the overall width of the gallery area, and have the thumbs float left to create a column effect.

  69. Correction, columns, instead of rows

    Thanks, Mark

  70. Hello,

    First question: Is it possible to create two rows of thumbnails?
    Because in the script there is one tag.

    Second question: Is it possible to use another file for the phote descriptions, like and HTML (HyperText Markup Language) include or something like that. If so, how do I implemant that.

    Greetings, Mark

  71. Thanks!

    Problem finally solved! I was searching in the wrong direction…

    Greetings, Mark

  72. The only edit you need to make is in index.php, on line 17 — the variable is called $path. This is where all of the code configuration is located, as described in the readme.txt file.

  73. Last question, do I need to change this in the gallery.php and title.php because I don’t know witch tags I need to change I have only knowledge of HTML (HyperText Markup Language) and CSS (Cascading Style Sheets) this is new for me.

  74. Yes, you do. The path you’ll be wanting should be easy to figure out, since most of it is reported in the error messages on your page!

  75. Hello,

    Thanks for the quick answer, do I need to change the path in the php script?


    Tanks, Mark

  76. Hi, Mark – you need to provide the server path to your images folder in the script configuration. The path /path/to/images/titles.txt is the example path provide in the download; you’ll be replacing this with your real server path.

    On your second error, I’m not sure what’s up there — the function in the download on line 11 should be fgets, not gets.


  77. Hello,

    I’m a starter with PHP (Hypertext PreProcessing), thats why I can’t solve this problem. When I uploaded the files to a special directory and open index.php this errors appear:

    Warning: fopen(path/to/images/titles.txt): failed to open stream: No such file or directory in /home/3/4/f/4480/4480/public_html/fotografie/includes/title.php on line 10

    Fatal error: Call to undefined function: gets() in /home/3/4/f/4480/4480/public_html/fotografie/includes/title.php on line 11

    Thanks, Mark ( Netherlands )

  78. Hi Joe. Great script. Very easy to implement into an existing site compared to all the other guff floating around the internet. I have quite a large header on my website and would like it so that when I click on one of the thumbnails or the “next” link that when the page reloads with the full sized image that it skips the header and jumps down the start of the thumbnails again. Can you help me implementing this as I don’t know enough about PHP (Hypertext PreProcessing) to try it myself!

    Thanks very much

  79. Yes – you can just leave them out. You’ll still want to include the pipe separators, but can actually leave any given field blank (except the image field, obviously).

  80. Hi Joe,

    Thanks for sharing your script. Perfect solution for what I was looking for (basically creating a gallery on my freenas implementation).

    Btw, is there a way to not require putting the titles of the pictures in the titles.txt file as I found that a bit cumbersome to do for each set of pictures I want to share (unless i’m missing something totally). Basically if I just want to quickly share some pictures without necessarily adding descriptions,etc.

    Thanks for your help.


  81. Hi Joe,

    Nice gallery. Hope you can create something that can handle multiple directories/albums.



  82. Just wanted to say thanks!
    Cheers /Mike

  83. Well, I’m not aware of anything that Ken may have done – but this is on my list of things to do in June and July, so it’s possible it’ll get done relatively soon!

  84. #

    I want her to be able to maintain the site on her own, so if I have time I may code an admin page that would allow her to select a photo to upload to her page, enter a title and description and then just hit a submit button that would automatically upload the photo and update the text file. If I get around to doing that, I’d be happy to share the code with you if you’d like to have it to add on to this.

    Regards, Ken

    Comment by Ken Anderson β€” January 24, 2009 @ 10:48 am

    Thanks, Ken – that would be great. It’s one of those things on my todo list, but since it’s been there for two years now it’s probably not going to happen soon!

    Comment by Joe Dolson (588 comments.) β€” January 24, 2009 @ 10:53 am

    Please help Ken and Joe. Ken did you do the update?. It sounds exactly what I am trying to do…and being almost 70 the mind is not what it used to be.
    Did you do the modifications” I would dearly hope that you have and that they could be kindly shared with the less tallented. Yours faithfully, Philip

  85. That’s great! Glad you were able to work things out!

  86. Manjusha Wadekar; May 28, 2009 at 11:21 am

    Hi Joe!

    Problem with the left alignment of the drop-down menu items solved!!! Now the items appear left aligned as I wanted to keep up with the style on the rest of the webspages!

    There is just a minor hitch! The width of the submenu items is 260 ox on all wenpagesm however it it slightly more on these PHP (Hypertext PreProcessing) photo galleries. I am trying to figure out the reason behind it! Hopefully that too shall resolve!

    You can check my handiwork by clicking on the following link:


    I feel so happy!!! THANK YOU ONCE AGAIN for all your help and putting up with my silly queries! I apologise if I have troubled you!

    Many thanks once again!
    Manjusha Wadekar

  87. Manjusha Wadekar; May 28, 2009 at 8:24 am

    Hi Joe!

    Just wanted to let you know that the problem with the ‘left’ alignment of the thumbnail photographs is SOLVED! Yes, removing the ‘wrap’ id from the index.php helped it! BUT the the drop-down menu items are still ‘center’ aligned. That problem is not resolved yet. Now the gallery no longer is centrally aligned but the drop-down menu items still are. Why? Any clue will be greatly appreciated!

    Manjusha Wadekar

  88. Manjusha Wadekar; May 27, 2009 at 11:04 pm

    Hi Joe!


    I did not look properly, the is used in the index.php file!! BUT there is which is an orphan (without its matching ) in that file! Initially when I had changed the index.php to accomodate my menu items and had removed the orphan . The index.php simply didn’t work. I wonder why? The index.php worked better when I removed #wrap (one and two s). There are 9 pairs in gallery.php and one pair and one orphan .

    My head has started spinning now! I know it is a very small minor fix but I am unable to do it. It is like a great programme that is not working because it doesn’t compile due to a stupid comma! I am unable to locate that comma!

    Once again SORRY for not looking at the script properly before writing to you about #wrap. Please accept the apologies!

    Thanks in advance for your help.
    Manjusha Wadekar

  89. Manjusha Wadekar; May 27, 2009 at 10:39 pm

    Hi Joe!

    Thank you so much for the clue! But I checked your downloaded gallery.php and found out that isn’t used anywhere! I did remove @wrap and its associated styles from the basic_styles.css but again the result is the same! There is a statement in gallery.php at the beginning. When I checked basic_styles.css, I did not find it defined there. Then I thought may be I should remove id=’gallery’ from the gallery.php file thinking that now it will not get to use any styles and then I can use my own. Surprise! I still have not got this problem resolved! It is still the same. Any other clue? If I have to define gallery style as left aligned how can I define it? (I am not a pro at CSS (Cascading Style Sheets) as I said before!)

    Please help! This problem has been bugging me for some time now!

    Anyway, the good thing is that using the same PHP (Hypertext PreProcessing) gallery that you wrote I managed to display text in place of thumbnails and thumbnails in place of the larger view and I turned the images into links to display even larger views in seperate windows!! It worked!!!! THANK YOU FOR A GREAT AND REALLY REALLY EASY SCRIPT!!! But the same problem of left-alignment of the drop-down menu persists though! However, there is no mis-alignment of the text that is being displayed in place of the thumbnails! Cool!!

    Thank you once again!
    Manjusha Wadekar

  90. I’m sorry I didn’t respond to your first comment – I started to reply, but ended up not having a chance to finish.

    At any rate, no – the #wrap styles and div are not necessary. They are in place for positioning on the sample page, but are not required in any way for the script to function. I suspect that simply removing the div id="wrap" and the associated styles would fix your problem.

    And, to answer some of your other questions — wrap is used to align the whole of the gallery body in the window. The text areas within the gallery are individually aligned in other ways.

    It’s my general assumption that people using the gallery will be applying it in their own unique ways, and will replace the majority of styles with their own.

  91. Manjusha Wadekar; May 27, 2009 at 12:10 pm

    Hi Joe!

    Let me rephrase my problem:

    Where is this ‘center’ alignment of the whole photo gallery located? I tried searching id ‘gallery’ used at the beginning of the gallery.php which isn’t defined there in the CSS (Cascading Style Sheets) basic_styles.css that you have provided. There is a ‘wrap’ class that you have defined in your CSS basic_styles.css which isn’t used anywhere in the PHPs (gallery.php or title.php). Are we supposed to use them? I don’t see the need. ‘wrap’ id has ‘center’ (used for text alignment) but if it isn’t used then why is the whole gallery ‘center’ aligned on the page? Or how is it aligned ‘center’? is ‘wrap’ a default id? A pre-defined id in CSS? Not user-defined? If I get a clue to this then probably the problem with my drop-down menu items which have been centered can be resolved. Also when the number of photos are odd (< num_per_page), the odd photo gets ‘center’ aligned again! That issue will also be resolved. I hate to use unnecessary, complicated classes and ids when simple things work. I am not exactly a novice to CSS but neither am I a pro to realize the problem in the CSS. However, the problem IS in CSS is the only thing I have figured out so far. Correct me if I am wrong. Please guide.
    Awaiting your reply and thanking you in advance for all the help.
    Manjusha Wadekar

  92. Manjusha Wadekar; May 23, 2009 at 8:44 am

    Hi Joe!

    Writing to you after quite some time! Your PHP (Hypertext PreProcessing) photo gallery is indeed easy to work with! However, while using it for the first time with the webpage that has drop-down menu items, I found out that the menu items in the drop down list became ‘center’ aligned which I don’t want! I want the menu items to be ‘left’ aligned! Can you please help?

    The webpage which has this problem is as follows:


    Please help! Rest all worked just the way I wanted! Thank you once again for a great script!

    Looking forward to your comments.


  93. Hi I’m not the best for scripts, but I made this to create a basic titles.txt from jpg-images in a folder labeled images below the index.php.

    cd images
    ls *.jpg | sed ‘s/$/||/g’ > titles.txt

  94. Interesting. Might be something about litehttpd which is causing that problem, I guess — it’s not a webserver I’ve tested the script on (or used at all, for that matter!) so it could be a candidate for something like that.

    Still, as long as you’ve solved the problem for yourself, I’m not going to worry about it too much. Thanks!

  95. Hi ,
    I’m using litehttpd, as used by FreeNAS (in webserver). With your sample images folder everything works (thumbnails). But when I switch to my foto folder, thumbnails are not shown unless in lowercase. Not a big deal, since i resolved to make all names lowercase.
    I added some nautilus scripts to help convert(size) & rename images.
    Added a custom background wallpaper image and everything is working – peachy!

    Thanks for a nice software.

  96. I’m really not sure that’s true, chang-li — although it’s definitely the case that the file names are case-sensitive, whether the image name is lowercase or uppercase should make absolutely no difference. I can’t reproduce any error at any rate; and there’s nothing in the script which depends on case other than the normal apache web server requirement that file names be case-matched.

  97. Nice program.I will now be able to use it.
    Thumbnails are not visible unless 1st letter of image name is lowercase.

  98. Great gallery for personal use. Thank you!

  99. script is great got it working on my own site thank you for making it πŸ™‚

  100. good script especially for those who dont like to program or mess with stuff like mysql

  101. figured it out.

    it was

    but thanks for everything!

  102. haha, yes i tried this one before πŸ˜‰
    but it result in a link looking like this.

    similar results if i use

    (yes, i know very little php so i go with experiment, eliminations, trial and errors… πŸ˜‰

  103. Ah – of course. Yes, the $image array is a multi-dimensional array. The image should be $image[$i][0].


  104. no actually i made a mistake in the last post.

    results in this link

    if i use the
    as a test; it gives me the result i’m looking for:

    the $photo[$i] become /images/picture_tn.jpg
    the $image[$i] become /images/Array

    now i need something that will give me /images/picture.jpg (without the _tn)

    if it’s too much problem; please don’t worry about it.
    I know you wrote this script more than 2 years ago.


  105. Cool. Glad that’s working for you! I was responding without really looking at the script, so I’m not surprised I picked the wrong variable…


  106. the
    results in this link

    if i use the
    as a test; it gives me the result i’m looking for:

    thanks for the help man, and once again thank you for this great script!

  107. I’m guessing that the problem is that you’re not actually seeing a link? With no link text or image, these links won’t be visible – they link should work with what you’ve written, but you’ll have some difficulty seeing it.

    In the second string, you’ll be needing to add the array indicator as well: $image[$i].

    Hope that helps! I’m not sure this is the problem you’re actually having, but it’s certainly a possibility, looking at the code you’ve supplied.

  108. ps: here is my problem.

    this work (link directly to the thumbnail image as a test)
    echo "\n<a href='$path/$photo[$i]' rel="nofollow"></a>";

    this doesn’t work (attempt to link at the bigger image)
    echo "\n<a href='$path/$image' rel="nofollow"></a>";

    I’ve tried many combinations (like $path/$image $path/[$i] )…
    all kind of different combinations but i guess i’m just on the wrong track here.

    Please help me out if you can.


  109. hello Joe

    Thank you so much for this gallery.

    I’ve been looking around the web for a long time to find a simple gallery that uses text files for description, paginations etc…

    I could install the gallery easily and it work great!

    It is very generous of you to share your codes with the world (reminds me of the movie “Hackers” πŸ˜‰

    Anyhow i was just wondering if you would be kind enough to help me get rid of the big image altogether?

    I just want the thumnails that link directly to the bigger version of the image (in a new window or whatever)

    Thank you so much once again; even if you don’t help me with my question, you are still AWESOME!

  110. Oh gee…I don’t know how to show it! Can I email it to you??

  111. Sorry Joe but the line didn’t show up in the last thread…here is what shows in my document:

    “echo “\n“;”

  112. I’m sorry! I made things rather confusing by copying the same code for both statements above…I’ve edited the code to be correct — you need to remove the img element and replace it with just the alt attribute text.

  113. Hmmm…I’m confused (*so sorry*)

    This is the line I’m finding: (line 123)
    echo “\n<a href=’?a=$i’ rel=”nofollow”></a>”;

    and I’m not sure what to modify? Do you mean that I need to remove this tag: <img src=’$path/$photo[$i]’
    and put in rel=”nofollow”?

  114. Glad you figured out the problem! Using text instead of images wouldn’t be a major revision; simply edit line 123 to replace:

    echo "\n
  115. $alt
  116. ";


    echo "\n$alt";

    Just be sure to provide an alt attribute text in your .txt source file!

  117. Hi Joe! So sorry but I did miss one thread comment and it had to do with using relative vs absolute path. I was using absolute path which caused the problem. Now fixed! Thanks!

    I’ve got a question though…what if I didn’t want to use thumbnails images but instead just use text as link to the large image? Could you help me with this or refer me to something that would help me out?

    Thanks so much!

  118. I’m a newbie at pHp coding and tried to find the answer through the comments above to no avail…I loaded all files to my server and changed the path to access the images. I can see everything with the exception of the thumbnail images. Should I be adding something to see them? Thanks for a great script!

  119. Thanks, Ken – that would be great. It’s one of those things on my todo list, but since it’s been there for two years now it’s probably not going to happen soon!

  120. Hi Joe,

    Thanks for putting this out there. I’m putting together a website for my sister’s housepainting business and needed a simple way to display photos for her portfolio and found this via a Google search. I haven’t had time to fully test it out yet, but looked at the demo and skimmed over the code and it looks like it might suit my purposes nicely. If I use it on the site, I’ll give you credit.

    I want her to be able to maintain the site on her own, so if I have time I may code an admin page that would allow her to select a photo to upload to her page, enter a title and description and then just hit a submit button that would automatically upload the photo and update the text file. If I get around to doing that, I’d be happy to share the code with you if you’d like to have it to add on to this.



  121. Thanks Krongsak! I appreciate your comments!


  122. Hello Joe,

    I can only second what most previous users said, great script, nicely written and easy to understand and tweak. Since I never really made the transition from table based layout to full css, I actually tweaked your code to use a table layout. Silly thing to do you’d say but it makes it so much easier to control the appearance of the gallery for someone not willing to burn hours on css hacks.
    I am having a last difficulty with the Next, previous link behaviors when getting to the last, first pic of the gallery, but I shall sort that promptly.

    Thanks again for this great script

  123. Thanks for catching that, Michael!

    It’s fixed in the download, now.

  124. On line 35:
    $current_page = (($a+1)%$num_per_page) ? intval(($a+1)/$num_per_page)+1 : intval(($a+1)/$num_per_page);

    I had to change the variable $a to $newa in order for the photos to cycle through the pages.

    This script is really good stuff.


  125. Got it. It really relates to your error reporting settings (which are set to show E_NOTICE level errors), but it’s a good thing to fix, anyhow.

    If you add this code before the for loop which is throwing the error (line 114, in my copy):

    if ($finish > ($result - 1)) {
    $finish = $result - 1;

    That’ll solve the problem. There’ll be a new version for download shortly.

  126. I don’t know if I can include a screen shot on here. When scrolling to the second page, I get two thumbnails, and then where the next thumbnails should be, I see:

    Notice: Undefined offset:6 in /user/sites/gallerytest/includes/gallery.php on line 116

    and then the same error repeats where the only difference is the offset is 7 instead of 6.

    Hope that explains it. The site is not public, so I cant demo it. Perhaps it is a PHP (Hypertext PreProcessing) version issue? I am testing this on a Mac, not Linux.


  127. Can you explain what you mean by ‘the index problem?’ I reviewed the previous comments, but I’m just not entirely clear what you mean.

    One common issue is if there are extra blank lines in the .txt file – this will cause extra image spaces to be generated, which can cause problems.

    I’m glad to help, but I’m just not certain what the problem is!

  128. Hi! Great scripts. I still seem to have the index problem if the number of pictures is not an even multiple of 4. A previous poster commented on this. Is this something I am doing wrong? I have not touched anything, just dropped all the files in my test website and changed the “images” directory path to point to your sample images. Thanks!

  129. Thanks, RJ! Glad it worked out for you! It’s not uncommon to need to add multiple inline declarations in CSS (Cascading Style Sheets) to get something to work right – the right combination of inline and block elements can be a bit tricky.

    The test page looks like it works pretty well!

  130. Hey Joe, thanks for this great piece of code its exactly what I was looking for.
    It took some work intigrating it into my php site, but it could also be that I went about it the hardest possible way since I have no actuall experiance with php code. I can however read and edit it.
    as you can see from My test page. I think it time it took was worth it.
    I ended up only using 3 parts of your basic css file in my theme’s exsiting css file, but recoded 2 of them. ie;

    #thumbs {
    width: 180px;
    ul.thumbs {
    display: inline;
    margin: 0;
    padding: 0;

    li.thumbs {display: inline;}

    Im not sure which inline caused the thumbs to tile horizonaly, it was lots of guess and check (I said i have little – no experiance right?)

    Now that I have it intigrated I’ll make use of the gallery links and just reuse the code for each section of the gallery.

    Again, thanks alot for the code!

  131. Hi Joe!
    Finally things worked out the way I wanted!!! THANK YOU SO MUCH FOR YOUR HELP AND A GREAT SCRIPT!! Please check out my handi-work by clicking on the following link:



  132. Hi Joe!
    Thank you so much for your input! I have a funny question to ask. I was able to see the changes I tried out in any of the PHPs but suddenly I am not seeing the photos on the web page at all. The error when clicked on the yellow warning icon on the left bottom corner of the screen shows something like below:

    Line: 124
    Char: 3
    Error: ‘null’ is null or not an object
    Code: 0
    url: http://www.kalyanibondre.com/index_photo.php

    I would be very grateful if you could visit the webpage by typing http://www.kalyanibondre.com and let me know what you think. The modified basic_styles CSS (Cascading Style Sheets) is as follows:

    #wrap {width: 0em; text-align: center; margin: 0 auto;}

    #thumbs {
    width: 180px;

    img {
    border: 1px solid #660000;
    padding: 1px;
    #full_image {
    float: right;
    width: 500px;
    border: 1px solid #660000;
    #gallery_nav {
    float: right;
    margin-top: 0em;
    border: 0px solid #ffffcc;
    padding: 0em;
    background: #ffffcc;

    Since I have a CSS written for my webpage I have tried modifying your CSS as above to keep up with the style on rest of the pages of the website.

    Please suggest what could be wrong. Why am I not able to see the results? Please let me know if I can send you your modified gallery.php as an attachment.

    Looking forward to your reply.
    Grateful Manjusha

  133. Glad you’re figuring things out, Manjusha! Ultimately, it’s the best way to learn. I’m not entirely clear what you did by removing the title and description part of the script; and removing those elements really shouldn’t have any effect on the position of the thumbnails.

    The thumbnails are moved to the left using the styles set in basic_styles.css. The important lines are lines 20-22 and lines 38-48 (in the original script), so if you’ve modified any of those it would make a difference. Hard to guess what’s happened without actually seeing the changes you’ve made, however!

  134. Hi Joe!
    Please ignore my earlier message! I found out what went wrong! Sorry to bother you!
    But now I have another question to ask. I have removed the Title, description part in your script (set to blanks). After that the thumbnail images shifted from left to the bottom of the screen. I want to keep the thumbnails to the left and enlarged image to the right with the caption of the photos below the enlarged image. While I could get to see the differences in the thumbnail sizes, font color, background color etc. I couldn’t get the thumbnails to stay put on the left and the enlarged image on the right. Please help me with that. It would be greatly appreciated.
    Thank you!

  135. Hi Joe!
    Finally figured out how to use your script and even make modifications such as color scheme, font etc. However when I added a new photo to the titles.txt file list, it didn’t display at all. Why? While I was testing with the existing photos the gallery worked fine. How do I add a new photo? Since all the photos are listed in a .txt file I thought adding new photos should not be a problem. But I guess I was wrong. Since PHP (Hypertext PreProcessing) means Hypertext Preprocessor, how do I resolve this problem of arrays of photos? Please help since I am a complete novice.
    Thank you for your help in advance.

  136. Hi!
    Thank you for your reply! I am looking for the instructions to incorporate your script to implement the photo gallery and I am stuck because I don’t know how to call your script in my HTML (HyperText Markup Language) file where I want to display the photos.
    Would be grateful if you can instruct me on how to implement your script.
    Thank you so much!

  137. Well, I’m not really sure what to say, Manjusha. Do you have a more specific problem to address? The script, while not totally self-explanatory, does contain a fair number of comments to help guide you through the process.

    I guess I’m not really clear what you’re looking for!

  138. Hi!
    Accidently came across your website while searching for implementing a photogallery for my assignment. But unfortunately being a complete novice, I couldn’t get exact details about implementing the photo gallery. I want to do something like Scott has done. Please guide me.
    Grateful Manjusha

  139. Sorry I was so late in responding here! Yeah, Windows uses a different file system, and I haven’t really worked on the script to make it usable on both servers. It’s on the list of things to do, but…just hasn’t happened yet.

    Glad you were able to solve your problem!

  140. nevermind, i switched my hosting account from windows to linux and the script works great, thanks alot

  141. Sorry, i should be more clear, i am able to access pictures with other parts of the site, simply using alink just not when using your php script

  142. thanks for the reply. the path in which my images are in is a folder named “images”, and I have set the path to: “./images” I am able to access other pictures from this folder. Does the gallery require gd library? I know one of the galleries I tried would not work because of this. Anyhow, thanks again for the reply.

  143. It’s hard to say what might be wrong without a bit more information. The most likely candidate, of course, is that the path is actually incorrect — but I hesitate to make any diagnosis with so little information!

  144. I like the looks of the script, but am having trouble using it. I placed the script within my page, and can’t seem to access any of the images in the images folder, though I believe I have the path name correct. I am very new to php, so any help is appreciated


  145. Thanks for the script! Very Handy!

  146. Go ahead and do as you will — I’m not really all that concerned about the licensing terms. I’d appreciate a link in some way; but I’m not going to insist on it.

  147. Hi Joe

    I am just learning PHP (Hypertext PreProcessing) & mysql at the moment and came across your great script.

    It does seem by far the most straightforward I have found.

    I would like to use it to help me learn PHP and adapt it to use on my own site eventually. To this end, the finished script would therefore be used commercially by my small business – what arrangement do you have for this?

    The designs I am working on would not allow an obvious acknowledgement to you as I am offering web design design services.

    Thanks in advance for your response.

    Best regards

    Ian Lain

  148. Thanks for your comments and compliments, Bob! I appreciate them. Removing the line break in the alt attribute would certainly be worthwhile – I’m not sure that’s the choice I’ll make for fixing it, but the comment is well and duly noted.

    I’ll confess that I may not have put as much attention as I could into the formatting of the code output – but your comments are welcome!

  149. Hi Joe
    To a PHP (Hypertext PreProcessing) novice (learning from David Power’s books), I find your wee script relatively easy to understand. I’ve broken it up, thrown it across different CSS (Cascading Style Sheets) layouts, played with the thumb lists (I was/am a Lego kid-says it all maybe) I’m having some fun with it. It’s a nice script Joe.

    I have a couple of tips, if I may be so bold.

    I noticed that in IE (Internet Explorer) (7 at least), the thumb alts (all but the last one) adds a line break (t’was driving me nuts :). In the titles.txt file, if one adds a Pipe after each line, it goes.

    And for the aligned-markup purists, on line 98 of gallery.php (the thumbs list), by adding \n immediately after the tag, the markup/source for the thumb list straightens up nicely too.

    Small as these ‘tips’ may be, I hope it’s of help to thy fellow novices. Again, nice script.

    Best regards

  150. Thanks, ah… “WeaponX” — I’ll get that fixed shortly.

  151. I was getting the following Error:

    Notice: Undefined offset: 5 in C:\Program Files\Apache Group\Apache2\htdocs\gallery\includes\gallery.php on line 95

    I noticed on line 94, in the for loop you have
    for($i = 0; $i <= $result; $i++)

    to resolve this issue you either have to remove the =, or use $result – 1

    if you have 5 pictures the loop is running 6 times, when we only want it to run 5… hope this helps

  152. Thanks, Aaron – I’ve fixed the sample gallery, and will replace the downloadable files very soon.

    I appreciate that — never noticed that bug!

  153. Not sure if you’re still interested in this script, but there appears to be a small mistake in the gallery include. When the last picture in the list is being viewed, the bug causes the “previous” link to link to the page being viewed (the last picture). It’s written as:

    case $suma:
    $prev = ($suma);
    $next = 0;

    It should be ($suma - 1). You can see the problem on your example page.

  154. No problem! πŸ˜‰

    Nice job implementing the script!

  155. Well, it seems I’m developing a track record for repeated posts. Please feel free to delete the prior. I meant to write: the redesigned site is at http://www.madisoncamaguey.org
    — Scott

  156. Well, the very simplest option would be to simply set up multiple galleries and link them manually. One of these days I’ll modify it for multiple galleries, but it’s not something I’ve seen any need for. Usually, I’ll just set up two or more separate gallery pages. All of the configuration happens within the gallery, so you can continue to use the same main gallery script, just reference a different image folder, gallery name, etc.

    Glad you appreciate it!

  157. Hi Joe,
    Thanks for what seems like a very simple yet elegant solution. It was up and running in no time flat, and the thumbnails worked as soon as I figured out the need to remove the spaces around the pipe symbol. I am a PHP (Hypertext PreProcessing) novice, so please forgive what may be a self-evident question. I have 40 images that I would like to show in two or more pages. Is there a straightforward method for doing that?
    — Scott

  158. Hi Joe,
    Thank you! This is exactly what I’m looking for. I’m a PHP (Hypertext PreProcessing) novice, so forgive a question, which may seem self-evident. I have roughly forty images that I would like to present in two pages. Can you suggest mods to support multiple pages?
    Many thanks,
    — Scott

  159. If you mean link to a specific image page in the gallery, certainly! Each image has a unique address.


    If you mean something else, of course, please clarify…

  160. Thanks for the help, it was a start i had it wrong. but after correcting the $path, it still didn’t working we found in the gallery.php script that the code was – if(is_file($path.’/’.$photo[$i])) { – we changed it to if(is_file(“$path/$photo[$i]”)); { and now it works fine.

    you have written a very nice piece of code. have another question and thank you for taking time to answer question on page. I overall don’t know a whole lot of PHP (Hypertext PreProcessing) but i can get by. my question is is there a way i can hard link to a image in the middle of the gallery have have it pick of of there?

    thanks again for taking time.

  161. Are you using an absolute path in for the variable $path? The path variable is used in an is_file() function, which doesn’t accept absolute paths in PHP (Hypertext PreProcessing) versions below 5.0. If you change it to a relative path, that would probably help.

  162. What to do if thumbnails are not showing up?? i have the in the same folder as my full size photos and are named filename_tn.jpg any ideas??

  163. Well, that’s curious. Can I see your implementation? That’s definitely not what should be happening…after the last image in the titles.txt file, it should wrap around to come back to the first image! (As you can see in my example script.

    Does your titles.txt file have blank lines after the final image? The file navigation script will read blank lines as if images were occupying them; so you have to make sure there aren’t any hard returns after the final image.

  164. I have downloaded and uploaded your script to my web host server. My question is as follows. I have an album that has 4 pictures. Which file do I need to update so that after the forth picture it does not continue to go to ex: php?a=4/php?a=5/php?a=6 etc?

    Other than this, this is a great script!

  165. Hi, Shu – Thanks for your comments. I don’t seem to have received your email, but I’ll send you a message shortly.

  166. Hi, Joe:

    How are you. I am trying to use your code of “Easy Php Gallery” for my small business application, such as to show a small stores products on their sites.

    I see you have limitation of the scripts for “non-commercial” use. Can you give me a price or something for my commercial use of your scripts?


    Shuya Huo
    P.S. I also sent you an email regarding a question for your another design work for a gallery business. Look forward to hear from you too.

  167. Slight change to the script made to improve security — effects the first 98 downloads.

  168. Thanks, Jermayn – hope you’re able to find it useful!

  169. Yeah I tried installing a photo gallery on a clients website/ blog the other day and it did not work, so I will defiantly have to have a look at this. Thanks for sharing πŸ™‚

  170. Thanks, Mike. I’ve looked at Thierry’s, too — but just didn’t want to deal with the complexity. I just didn’t WANT more from the script. My principle use for this is putting personal photos online for my family, actually — and I found that the longer it took the less likely I was to do it!

    By the way, while I was checking on that missing photo (more accurately, it was a “present and not supposed to be” entry in the titles file…), I found an error in the script – a variable which I inconveniently misnamed between the configuration and the gallery script. Somehow made it not quite work right…

    Only matters to the first 9 copies downloaded.

  171. Great job, Joe! That’s really quite nice. I will probably use that at some point, depending on the situation.

    I was considering using my AutoRun as a gallery (the automatic part might be cool). I have used Thierry Koblentz’s easyAlbum since it’s pretty good albeit complex to install I think. I only used Thierry’s once, but it was modded heavily at the client’s request which actually made my life miserable for a few days.

    I think one of your photos is missing by the way: “a1”