Skip to content

Instantly share code, notes, and snippets.

@ravikiranj
Created March 26, 2011 06:05
Show Gist options
  • Save ravikiranj/888060 to your computer and use it in GitHub Desktop.
Save ravikiranj/888060 to your computer and use it in GitHub Desktop.
PHP Logic for Uploading Photo to Flickr
<?php
//Include phpFlickr
require_once("phpFlickr/phpFlickr.php");
$error=0;
$f = null;
if($_POST){
if(!$_POST['name'] || !$_FILES["file"]["name"]){
$error=1;
}else{
if ($_FILES["file"]["error"] > 0){
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}else if($_FILES["file"]["type"] != "image/jpg" && $_FILES["file"]["type"] != "image/jpeg" && $_FILES["file"]["type"] != "image/png" && $_FILES["file"]["type"] != "image/gif"){
$error = 3;
}else if(intval($_FILES["file"]["size"]) > 525000){
$error = 4;
}else{
$dir= dirname($_FILES["file"]["tmp_name"]);
$newpath=$dir."/".$_FILES["file"]["name"];
rename($_FILES["file"]["tmp_name"],$newpath);
//Instantiate phpFlickr
$status = uploadPhoto($newpath, $_POST["name"]);
if(!$status) {
$error = 2;
}
}
}
}
function uploadPhoto($path, $title) {
$apiKey = "__your__app__apikey__";
$apiSecret = "__your__app__secret__";
$permissions = "write";
$token = "__your__generated__token__";
$f = new phpFlickr($apiKey, $apiSecret, true);
$f->setToken($token);
return $f->async_upload($path, $title);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment