');
}
}
/*
* stop_debugging
* closes the debugging log file
*/
function stop_debugging(){
global $debugging;
global $log_ref;
if($debugging){
fclose($log_ref);
}
}
/* debug to file cause flash has no clue */
$log_path = '/zoto/apache_web/static_pages/debug.txt';
$log_ref = null;
$upload_success = false;
/* split out our domain name */
$domain = split("[.:]", $_SERVER['HTTP_HOST']);
$domain = ($domain[1] . "." . $domain[2]);
/*if we're on org we want to turn on the debugging flag*/
$debugging = (strpos($_SERVER['HTTP_HOST'],'.org') === false )?false:true;
start_debugging();
/* get our username and token from the cookie */
$auth = null;
if(array_key_exists('auth_hash', $_COOKIE)){
logDebug("auth by cookie");
$auth = split("[:]", $_COOKIE['auth_hash']);
} else if(array_key_exists('auth', $_GET)){
logDebug('auth by get');
$auth = split("[:]", $_GET['auth']);
} else {
logDebug("Unable to auth user");
trigger_error("Unable to auth user.");
}
$auth_username = $auth[0];
$auth_token = $auth[2];
/* set up our ZAPI call parameters */
//$zapi_hostname = $_SERVER['SERVER_ADDR'];
//$zapi_hostname = "www.zoto.com";
$zapi_hostname = "www.".$domain;
$zapi_port = 80;
$zapi_location = "/RPC2";
$zapi_key = "5d4a65c46a072a4542a816f2f28bd01a";
$zapi_auth = array("username"=>$auth_username, "token"=>$auth_token);
$zapi_function = "images.add";
$uploaddir = '/zoto/apache_web/static_pages/uploads/';
$uploadfile = $uploaddir . basename($_FILES['Filedata']['name']);
logDebug($uploadfile);
$image_filename = basename($_FILES['Filedata']['name']);
$media_id = '';
$error_msg = 'there was a problem with the server';
logDebug('number of files uploaded ' . count($_FILES));
foreach ($_FILES as $key => $value) {
logDebug("Key: $key; Value: $value");
}
/* here's where we actually do the work */
if($auth[0] != null){
if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadfile)) {
logDebug("File is valid, and was successfully uploaded.");
/* open and read in the image file data */
$handle = fopen($uploadfile, "r");
$media_binary = fread($handle, filesize($uploadfile));
xmlrpc_set_type(&$media_binary, "base64");
fclose($handle);
unlink($uploadfile);
/* build the args for the XML-RPC query */
$zapi_query = array($image_filename, $image_filename, "", $media_binary);
/* send it to the zoto server */
$result = zapi_call($zapi_key, $zapi_auth, $zapi_function, $zapi_query);
if (is_array($result)) {
foreach ($result as $key => $value) {
logDebug("Key: $key; Value: $value");
}
if($result[0] == '0'){
$upload_success = true;
global $media_id;
$media_id = $result[1];
} else if($result[0] == '-1'){
global $error_msg;
$error_msg = $result[1];
}
}
} else {
logDebug("no file specified for upload!");
$error_msg = 'no file was specified to upload';
}
} else {
logDebug("User was not authed");
$error_msg = 'you must be logged in to upload photos';
}
stop_debugging();
?>