#!/usr/bin/php -q // e.g.: flickrdl.php /tmp 25 $dir = $_SERVER['argc'] > 1 ? $_SERVER['argv'][1] : '.'; $num = $_SERVER['argc'] > 2 ? $_SERVER['argv'][2] : 1; // Send an API request to get the image list $res = file_get_contents("http://api.flickr.com/services/rest/?". "method=flickr.interestingness.getList". "&api_key=$key&per_page=$num"); // Parse the XML response $search = new SimpleXMLElement(trim($res)); if ($search['stat'] == 'fail') die($search->err[0]['msg']); // Iterate over each photo foreach ($search->photos[0] as $photo) { // Print photo ID for debugging/notification print "{$dir}/{$photo['id']}.jpg\n"; // Download the image and save to local file copy("http://static.flickr.com/{$photo['server']}". "/{$photo['id']}_{$photo['secret']}.jpg", "{$dir}/{$photo['id']}.jpg"); } ?>