Let's say I have 6 folders of photos (living on a different server). How would you go about displaying them with thumbnails (thumbs will live on the other server too)? With a similar outcome to what I already have.
I don't remember the details of the outcome you currently have, but it's all pretty simple.
Every X minutes and/or when executing a particular script, do a directory listing for the parent directory of those six folders, and cache the results in a local text file (or if they are separate galleries do one file per folder).
Directory listing can be over HTTP or FTP or REST API or whatever - specifics of that will depend on what server supports and how easy PHP can do the appropriate things. (Search for if PHP can do virtual filesystems, if not, look at the appropriate FTP/file related functions.)
Then to output the files you just split it per line, like you already did before. Thumbnails can either be in a sub-directory with same filename, or be named filename.thumb.jpg, so you only need to do the listing once, and just output the a/href differently to the img/src.