diff --git a/rcc/api/media/index.php b/rcc/api/media/index.php new file mode 100644 index 0000000..6efca5f --- /dev/null +++ b/rcc/api/media/index.php @@ -0,0 +1,46 @@ +getConfig(); + +if ($settings["rcc"]["api"] == "on" && $settings["rcc"]["rcc"] == "on") { + $app = new \Slim\App(); + + /** + * api for uploading files + * + * @return JSON json string with status + */ + $app->post('/', function (Request $request, Response $response) { + $storage = new \Upload\Storage\FileSystem('../../../media/'); + $file = new \Upload\File('file', $storage); + + try { + $file->upload(); + $data = array("code" => 201); + $response = $response->withHeader('Content-type', 'application/json'); + $response = $response->withJson($data, 201); + } catch (\Exception $e) { + $errors = $file->getErrors(); + $data = array("code" => 500, "error" => $Errors); + $response = $response->withHeader('Content-type', 'application/json'); + $response = $response->withJson($data, 500); + } + + return $response; + }); + + $app->run(); +}