UploadDataAction.class.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class UploadDataAction implements IAction {
  3. public function execute() {
  4. var_dump($_POST);
  5. var_dump($_FILES);
  6. die();
  7. if(!Authorize::isLoggedIn() || !Authorize::hasPermission()) {
  8. return array("error" => "Access not authorized");
  9. }
  10. //http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
  11. /*
  12. PUT /ObjectName HTTP/1.1
  13. Host: BucketName.s3.amazonaws.com
  14. Date: date
  15. Authorization: authorization string (see Authenticating Requests (AWS Signature Version
  16. 4))
  17. */
  18. $bucket = $_POST['bucket'] ?? $_GET['bucket'] ?? "";
  19. $project = $_POST['project'] ?? $_GET['project'] ?? "";
  20. $displayName = $_POST['display_name'] ?? $_GET['display_name'] ?? "";
  21. //TODO: scrub inputs
  22. if(empty($bucket) || empty($displayName) || empty($project)) {
  23. return array("error" => "One or more required fields missing: bucket, project, display_name");
  24. }
  25. $sql = "INSERT INTO projects (bucket, folder, display_name)
  26. VALUES
  27. (:bucket, :folder, :display_name);";
  28. $db = SqliteDatabase::getSingleton();
  29. $preparedQuery = $db->prepare($sql);
  30. $preparedQuery->bindValue(':bucket', $bucket);
  31. $preparedQuery->bindValue(':folder', $project);
  32. $preparedQuery->bindValue(':display_name', $displayName);
  33. try {
  34. $result = $preparedQuery->execute();
  35. return array("status" => "success", "message" => "Successfully created project '" . $displayName . "'.");
  36. }
  37. catch(Exception $e) {
  38. return array("error" => "Error when creating project '" . $displayName. "': possibly duplicate?" , "exception" => $e->getMessage());
  39. }
  40. }
  41. }