Esempio n. 1
0
        header("Content-Type: text/html");
        print json_encode(array("status" => "error", "errors" => $file->getErrors()));
        exit;
    }
});
$app->post('/upload/file', function () use($app) {
    // Setup file storage
    $file_storage = new \Upload\Storage\FileSystem("../assets/files");
    $file = new Upload\File("file", $file_storage);
    $file->addValidations(array(new Upload\Validation\Mimetype(array('application/pdf'))));
    $file->setName(uniqid());
    try {
        // Success!
        $file->upload();
        header("Content-Type: text/html");
        print json_encode(array("status" => "success", "filename" => $file->getName() . '.' . $file->getExtension()));
        exit;
    } catch (\Exception $e) {
        header("Content-Type: text/html");
        print json_encode(array("status" => "error", "errors" => $file->getErrors()));
        exit;
    }
});
$app->get("/mailsubscription/:uid", function ($uid) {
    try {
        $mailSubscription = MailSubscription::getByUserId($uid);
        $subscribed = true;
    } catch (MailSubscriptionNotFoundException $e) {
        $subscribed = false;
    }
    outputJSON(array("subscribed" => $subscribed));
Esempio n. 2
0
 public function uploadMedia(Request $request, Response $response, $arguments)
 {
     $errors = [];
     foreach ($_FILES as $key => $file) {
         $storage = new \Upload\Storage\FileSystem('uploads');
         $file = new \Upload\File($key, $storage);
         try {
             $file->setName(s($file->getName())->slugify());
             $file->upload();
         } catch (\Exception $e) {
             array_push($errors, 'Failed to upload ' . $file->getNameWithExtension());
         }
     }
     return $response->withJson(['errors' => $errors], 200, JSON_PRETTY_PRINT);
 }