2016-04-18 11:04:41 +02:00
|
|
|
<?php
|
|
|
|
// Marcel Kapfer (mmk2410)
|
|
|
|
// License: MIT License
|
|
|
|
// api for uploading files
|
|
|
|
|
|
|
|
use \Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
use \Psr\Http\Message\ResponseInterface as Response;
|
|
|
|
|
|
|
|
require '../../../vendor/autoload.php';
|
|
|
|
require '../../../res/php/Config.php';
|
|
|
|
require '../../../res/php/ArticleGenerator.php';
|
|
|
|
|
|
|
|
use \mmk2410\rbe\config\Config as Config;
|
|
|
|
|
|
|
|
$config = new Config("../../../config.yaml", '../../../vendor/autoload.php');
|
|
|
|
$settings = $config->getConfig();
|
|
|
|
|
2016-05-17 22:36:26 +02:00
|
|
|
include '../auth/auth.php';
|
|
|
|
|
2016-04-18 11:04:41 +02:00
|
|
|
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();
|
|
|
|
}
|