public function doPost()
 {
     try {
         // we support both a raw http post (without application/x-www-form-urlencoded headers) like java does
         // and a more php / curl safe version of a form post with 'request' as the post field that holds the request json data
         if (isset($GLOBALS['HTTP_RAW_POST_DATA']) || isset($_POST['request'])) {
             $requestParam = urldecode(isset($_POST['request']) ? $_POST['request'] : $GLOBALS['HTTP_RAW_POST_DATA']);
             if (get_magic_quotes_gpc()) {
                 $requestParam = stripslashes($requestParam);
             }
             $request = json_decode($requestParam);
             if ($request == $requestParam) {
                 throw new Exception("Malformed json string");
             }
             $handler = new MetadataHandler();
             $response = $handler->process($request);
             echo json_encode(array('gadgets' => $response));
         } else {
             throw new Exception("No post data set");
         }
     } catch (Exception $e) {
         header("HTTP/1.0 500 Internal Server Error", true, 500);
         echo "<html><body><h1>Internal Server Error</h1><br />";
         if (Config::get('debug')) {
             echo $e->getMessage() . "<br /><pre>";
             print_r(debug_backtrace());
             echo "</pre>";
         }
         echo "</body></html>";
     }
 }
<?php

/*
 * jQuery File Upload Plugin PHP Example 5.14
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2010, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */
error_reporting(E_ALL | E_STRICT);
require 'MetadataHandler.php';
require 'UploadHandler.php';
if (isset($_GET["action"]) && trim($_GET["action"]) === 'submissions') {
    $metadata_handler = new MetadataHandler();
    $allSubmissions = $metadata_handler->getAll();
    echo json_encode($allSubmissions);
} else {
    if (isset($_GET["action"]) && trim($_GET["action"]) === 'filesList' && isset($_GET["id"])) {
        $upload_handler = new UploadHandler();
        $upload_handler->initialize();
    } else {
        die('Not supported request.');
    }
}
<?php

/*
 * jQuery File Upload Plugin PHP Example 5.14
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2010, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */
error_reporting(E_ALL | E_STRICT);
require_once 'MetadataHandler.php';
require_once 'UploadHandler.php';
require_once 'MailHandler.php';
if (isset($_GET["payload"]) && trim($_GET["payload"]) === 'metadata') {
    $metadata_handler = new MetadataHandler();
    $id = $metadata_handler->saveMetadata($_POST["title"], $_POST["description"], $_POST["author"], $_POST["email"], $_POST["time"], $_POST["geo"], $_POST["source"]);
    try {
        $mail_handler = new MailHandler();
        $mail_handler->notifyAdmins($id, $_POST["title"], $_POST["description"], $_POST["author"], $_POST["email"], $_POST["time"], $_POST["geo"], $_POST["source"]);
    } catch (Exception $e) {
        error_log("Couldn't send email" . $e->getMessage());
    }
    echo json_encode('{"id":' . $id . '}');
} else {
    $upload_handler = new UploadHandler();
    $upload_handler->initialize();
}