1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- class UploadDataAction implements IAction {
- public function execute() {
- var_dump($_POST);
- var_dump($_FILES);
- die();
- if(!Authorize::isLoggedIn() || !Authorize::hasPermission()) {
- return array("error" => "Access not authorized");
- }
-
- //http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
- /*
- PUT /ObjectName HTTP/1.1
- Host: BucketName.s3.amazonaws.com
- Date: date
- Authorization: authorization string (see Authenticating Requests (AWS Signature Version
- 4))
- */
- $bucket = $_POST['bucket'] ?? $_GET['bucket'] ?? "";
- $project = $_POST['project'] ?? $_GET['project'] ?? "";
- $displayName = $_POST['display_name'] ?? $_GET['display_name'] ?? "";
-
- //TODO: scrub inputs
- if(empty($bucket) || empty($displayName) || empty($project)) {
- return array("error" => "One or more required fields missing: bucket, project, display_name");
- }
-
- $sql = "INSERT INTO projects (bucket, folder, display_name)
- VALUES
- (:bucket, :folder, :display_name);";
- $db = SqliteDatabase::getSingleton();
- $preparedQuery = $db->prepare($sql);
- $preparedQuery->bindValue(':bucket', $bucket);
- $preparedQuery->bindValue(':folder', $project);
- $preparedQuery->bindValue(':display_name', $displayName);
- try {
- $result = $preparedQuery->execute();
- return array("status" => "success", "message" => "Successfully created project '" . $displayName . "'.");
- }
- catch(Exception $e) {
- return array("error" => "Error when creating project '" . $displayName. "': possibly duplicate?" , "exception" => $e->getMessage());
- }
- }
- }
|