Created
March 26, 2011 06:05
-
-
Save ravikiranj/888060 to your computer and use it in GitHub Desktop.
PHP Logic for Uploading Photo to Flickr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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