function processImage($uploadDir, $filename) { $uploadedFile = combine($uploadDir, $filename); //save exif data $message = "File uploaded."; $exif = getImageMetadata($uploadedFile); $dateTaken = getExifDateTaken($uploadedFile, $exif); if (!$dateTaken) { $dateTaken = getDateFromFilename($filename); } if (!$dateTaken) { $dateTaken = getFileDate($uploadedFile); } $exif["dateTaken"] = $dateTaken; $description = arrayGetCoalesce($exif, "ImageDescription", "IPTC.Caption"); $description = trim($description); writeCsvFile("{$uploadedFile}.txt", $exif); writeTextFile("{$uploadedFile}.js", jsValue($exif)); //resize images and keep hd version $sizes = getConfig("thumbnails.sizes"); $resized = resizeMultiple($uploadDir, $filename, $sizes); $keep = getConfig("thumbnails.keep"); if ($keep) { moveFile("{$uploadDir}/.{$keep}", $filename, $uploadDir); deleteDir("{$uploadDir}/.{$keep}"); unset($resized[$keep]); } if ($dateTaken) { setFileDate($uploadedFile, $dateTaken); } $vars = get_defined_vars(); $result = array(); $exif["meal"] = selectMeal($dateTaken); $result["_exif"] = $exif; $result["success"] = true; return addVarsToArray($result, "filename filesize mimeType dateTaken description", $vars); }
<?php require_once "../include/includes.php"; setContentType("text", "plain"); session_start(); echo jsValue($fpConfig, true);
require_once "../include/includes.php"; setContentType("text", "plain"); session_start(); $db = new SqlManager($fpConfig); $postJson = getJsonPostData(); $action = reqParam("action"); if (!$action) { $action = @$postJson["action"]; } $username = fpCurrentUsername(); $response = array(); switch ($action) { case "saveForm": //save form: insert,update,delete user_answers for this user $user_answers = $postJson["formData"]; $result = saveAnswers($db, $username, $user_answers); $response = array("answers" => count($user_answers), "result" => $result); break; case "form_questions": default: $response["questions"] = getFormQuestions($db, $_REQUEST); if ($username) { $response["user_answers"] = $db->selectWhere(array("table" => "user_answer", "username" => $username)); } } $db->disconnect(); $response["queries"] = $db->getLog(); $response["time"] = getTimer(true); echo jsValue($response);
$username = fpCurrentUsername(); $upload_id = reqParam("upload_id"); debugVar("username", true); debug("Request", $_REQUEST); debug("GET request", $_GET); debug("POST request", $_POST); debug("POST files", $_FILES, true); if (!$username) { return errorMessage("Not logged in."); } if (!$upload_id) { return errorMessage("No File deleted."); } $db = new SqlManager($fpConfig); if ($db->offline) { return errorMessage("DB offline. No File deleted."); } //if profile filters( Q_ ) : demographic //otherwise: personal $params = array("table" => "user_upload"); addVarsToArray($params, "username upload_id"); //$results = demographicPortrait($db, $params); $success = $db->delete($params); $message = $success ? "record {$upload_id} deleted." : "record id {$upload_id} not deleted."; $db->disconnect(); //TODO delete image file: check if other records for this user use this filename. if only 1, delete file and its thumbs. $response = array(); addVarsToArray($response, "success message upload_id"); $response["time"] = getTimer(true); echo jsValue($response, true, true);
function jsValue(&$value) { switch (gettype($value)) { case 'double': case 'integer': return $value > 0 ? $value : '"' . $value . '"'; case 'boolean': return $value ? 'true' : 'false'; case 'string': return '"' . str_replace(array("\n", "\\b", "\t", "\f", "\r"), array('\\n', '\\b', '\\t', '\\f', '\\r'), addslashes($value)) . '"'; case 'NULL': return 'null'; case 'object': return '"Object ' . addslashes(get_class($value)) . '"'; case 'array': if (isVector($value)) { foreach ($value as $v) { $result[] = jsValue($v); } return '[' . implode(',', $result) . ']'; } else { $result = '{'; foreach ($value as $k => $v) { if ($result != '{') { $result .= ','; } $result .= jsValue($k) . ':' . jsValue($v); } return $result . '}'; } default: return '"' . addslashes($value) . '"'; } }