Uploading a photo
This sample shows how to upload all the JPG files in a directory to Flickr. Take a look at the PhlickrUploader script listed on the tools page for a more complete uploading example.
<?php
// use the GetToken.php script to generate a config file.
define('API_CONFIG_FILE', './authinfo.cfg');
define('UPLOAD_DIRECTORY', 'D:/sf/phlickr/samples/files_to_testupload');
define('PHOTO_EXTENSION', '.jpg');
require_once 'Phlickr/Api.php';
require_once 'Phlickr/Uploader.php';
$api = Phlickr_Api::createFrom(API_CONFIG_FILE);
if (! $api->isAuthValid()) {
die("invalid flickr logon");
}
$uploader = new Phlickr_Uploader($api);
$photo_ids = array();
// Use the Standard PHP Library's DirectoryIterator to list all the files in
// the directory.
$di = new DirectoryIterator(UPLOAD_DIRECTORY);
foreach($di as $item) {
// only files with the given extension...
if ($item->isFile()) {
if (substr(strtolower($item), - strlen(PHOTO_EXTENSION)) === strtolower(PHOTO_EXTENSION)) {
print "Uploading $item...\n";
$photo_id[] = $uploader->upload($item->getPathname(), strtolower($item), '', 'some tags');
}
}
}
if (count($photo_ids)) {
printf("All done! If you care to make some changes:\n%s", $uploader->buildEditUrl($photo_ids));
}
?>





