예제 #1
0
            return $_GET['callback'] . '(' . json_encode($data) . ');';
        } else {
            return json_encode($data);
        }
    }
    public function isPost()
    {
        return isset($_POST) && count($_POST) > 0 || isset($_FILES) && count($_FILES) > 0;
    }
    public function getPostInput($field)
    {
        if (!$this->isPost()) {
            return;
        }
        // It's a file input
        if (isset($_FILES[$field])) {
            // Reorder the data
            $result = array();
            foreach ($_FILES[$field]['name'] as $k => $d) {
                $result[] = array('name' => $d, 'size' => $_FILES[$field]['size'][$k], 'tmpfile' => $_FILES[$field]['tmp_name'][$k], 'error' => $_FILES[$field]['error'][$k]);
            }
            return $result;
        }
        if (isset($_POST[$field])) {
            return $_POST[$field];
        }
    }
}
$server = new RestServer();
$server->response();
예제 #2
0
 /**
  * POST Method to create new user
  */
 public function postAddUser()
 {
     $post = $this->getPost();
     if (!$this->validatePost('name', 'user', 'pass')) {
         return RestServer::throwError(Language::CANNOT_BE_BLANK('Name, User and Pass'), 400);
     }
     $userData = array('name' => $post['name'], 'username' => $post['user'], 'passwd' => CR::encrypt($post['pass']), 'email' => $post['email']);
     $this->newModel('auth');
     $this->model('auth')->insertUser($userData);
     if (!$this->model('auth')->queryOk()) {
         if ($this->model('auth')->getErrorCode() == 23000) {
             return RestServer::throwError(Language::USER_ALREADY_TAKEN(), 400);
         } else {
             return RestServer::throwError(Language::QUERY_ERROR(), 500);
         }
     }
     return RestServer::response(array('status' => 200, 'uid' => $this->model('auth')->getLastInsertId(), 'message' => 'User created!'), 200);
 }