mnmlist: Gallery2 to Flickr Migration

For half a decade, I have depended on the great open source Gallery2 project to host my photo galleries. Unfortunately, I am finding myself with less and less time to devote to maintaining the installation, and many useful social media features have yet to make it into its code base. So, I finally decided to port my entire gallery into flickr.

Much to my surprise, there are lots of scripts in the gallery database to import photos from flickr, but no functional scripts to export photos out of gallery2 into flickr. Several past attempts have been made, but I can get none of them to work properly. So I did what any good coder would do, I modified the existing scripts until it worked. I am providing the scripts I hacked at the end of this post. There are several caveats with the scripts that I’m including here:

  1. It’s recommended that you run this script (export-gallery.php) using command line php, or else the script might pre-maturely end due to Apache rest times. I also have max_execution_time = 0 set in my php.ini.
  2. It’s recommended that you dramatically increase resource limitations on your mysql server when attempting to run this script. I made no attempt at optimizing mysql calls at all. The script basically makes a new call whenever it wants new data. I have wait_timeout=600 set in my my.cnf.
  3. I offer NO support whatsoever for these scripts. They were created to ease my own personal transitions, and reading them should be fairly easy.
  4. The script utilizes PHPFlickr and is based on‘s version of export-gallery. Several major upgrades to the original script have been made, including the ability to export sub-albums.
  5. I recommend only using getToken.php in phpFlickr, as I personally could not get PHPFlickr’s API authentication to work in any reliable fashion.
  6. You should see a line like this in export-gallery.php i.".DATABASE_COLUMN_PREFIX."ownerId=10 AND . This allows you to export galleries on a per-user basis. You can look up the userid information in the gallery2 tables.

So with that said, click here to download the script. You can run it by typing php export-gallery.php on the command line after editing a few variables at the top of export-gallery.php and setting up the API key / token combination from flickr. I used this very useful link from PHPFlickr to get my token after setting up the API key.