• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
makerhacks-logo

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • YouTube
  • Free Arduino Course
  • Recommendations
  • Contact

PHP Script to Backup Flickr Photosets

You are here: Home / Software and Programming / PHP Script to Backup Flickr Photosets
FacebookTweetPin
Author: Chris Garrett
Flickr Backup

Years ago I wrote a PHP script to download photographs from Flickr. That was the previous time the company changed hands, when it was sold to Yahoo! I am not sure I want to keep my photos on Flickr again so I brought my script up to date and made it iterate through all my albums so I could download everything in original resolution. Check it out.

PHP Code

If you just want to try it, you can download from my Git repo here.

<?php

/*
	PHP SCRIPT TO BACK UP FLICKR PHOTOSETS

	Arguments:
	
	APIKEY, SECRET, FLICKER_USER
	
*/

require_once("phpFlickr.php");

$key = $argv[1];
$secret = $argv[2];
$user = $argv[3];



$f = new phpFlickr( $key, $secret );




// set the script to never time out

set_time_limit(0);

ini_set('error_reporting', E_ALL);

if($f) print "API ok ...\n\n";


$sets = $f->photosets_getList( $user )['photoset'];



 
foreach ( $sets as $set )
{
	

	$set_name = $set['title']['_content'];
	
	$folder = makeFilename( $set_name );
	
	// get the photos from a set
	
	$photos = $f->photosets_getPhotos( $set['id'] );
	
	
	if($photos) print " got $folder photos ..\n\n\n";
	
	// Loop through the photos and output the html
	process_set( $photos['photoset'], $folder, $f ) ;

}




function process_set( $photos, $folder, $f )
{	
	foreach ($photos['photo'] as $photo) {
	
		 
		
		// get image URLs
		
		$photoSizes = $f->photos_getSizes($photo['id']);
		
		$originalSizeURL = $photoSizes[count($photoSizes) - 1]['source'];
		
		$thumbURL = $f->buildPhotoURL($photo, "square");
		
		 
		
		// display the thumbnail
		
		print $photo['title'] . " [$originalSizeURL]" ."\n";
		
		 
		
		// download the original version
		
		grabPic( $originalSizeURL, $folder, $photo['title']."_".$photo['id']);
		
	
	}
}


function file_get( $filename, $url )
{
	$ch = curl_init ($url);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	$rawdata=curl_exec($ch);
	curl_close ($ch);
	
	$fp = fopen( $filename,'w');
	fwrite($fp, $rawdata);
	fclose($fp);
}

 

function grabPic( $URL, $folder, $title)

{
	
	if ( !file_exists( "./" . $folder )) {
    	mkdir(  "./" . $folder, 0777, true );
	}


	$filename = $folder . "/" . makeFilename($title).".jpg";
	
	$source = $URL;
	
	$newimage = file_get($filename, $source);

}

 

function makeFilename($string)
{
	return preg_replace("/[^A-Za-z0-9]/", "_", $string);
}


?>
Category: Software and ProgrammingTag: Hacks, photography, php
FacebookTweetPin

About Chris Garrett

Marketing nerd by day, maker, retro gaming, tabletop war/roleplaying nerd by night. Co-author of the Problogger Book with Darren Rowse. Husband, Dad, ?? Canadian.

Check out Retro Game Coders for retro gaming/computing.

☕️ Support Maker Hacks on Ko-Fi and get exclusive content and rewards!

Previous Post:Wasted ABS filament Filament Review
Next Post:Anet A8 for only $155.99anet a8 3d printer kit review

Sidebar

  • Facebook
  • Twitter
  • Instagram
  • YouTube

Join the Newsletter

Sign up and get a free Arduino course + more!

Subscription Form

Recently Popular

  • xTool S1 Review
  • xTool P2 Review (first look)
  • IKIER K1 Pro Max Review
  • Gweike Cloud Review
  • How to choose the right 3D printer for you
  • Glowforge Review – Glowforge Laser Engraver Impressions, Plus Glowforge Versus Leading Laser Cutters
  • Flux Ador
  • Prusa i3 Mk3S Review
  • Best 3D Printing Facebook Groups
  • xTool D1 Pro Laser Cutter Review
  • Elegoo Mars Review – Review of the Elegoo Mars MSLA Resin 3D Printer
  • Glowforge ‘Pass-Through’ Hack: Tricking the Front Flap of the Glowforge with Magnets to Increase Capacity
  • How to Make a DIY “Internet of Things” Thermometer with ESP8266/Arduino
  • Wanhao Duplicator i3 Review
  • IKEA 3D Printer Enclosure Hack for Wanhao Di3
  • Creality CR-10 3d printer review – Large format, quality output, at a low price!
  • 3D Printed Tardis with Arduino Lights and Sounds
  • Anet A8 Review – Budget ($200 or less!) 3D Printer Kit Review
  • Make your own PEI 3D printer bed and get every print to stick!
  • Upgrading the Wanhao Di3 from Good to Amazing
  • How to Install and Set Up Octopi / Octoprint
  • Creality CR-10 S5 Review
  • Glowforge Air Filter Review
  • Thunder Laser Review

30 Days to Arduino

Arduino Tutorials
  • 3D Printing
  • CNC
  • Electronics and Hardware
  • Laser Cutting
  • News and Reviews
  • Software and Programming

arduino budget cad cnc diode laser glowforge Hacks Ideas laser cutter linux Makes making python raspberry pi resin Reviews technology tips xTool Lasers

.

Maker Hacks Blog Copyright © 2026 · All Rights Reserved · Privacy Policy