Esempio n. 1
0
    return $app->render('home.html.twig');
});
$app->get('/tidus_laugh.{ext}', function ($ext) use($app) {
    $sth = $app['db']->prepare('SELECT mime_type FROM extensions WHERE extension = ?');
    $sth->bindValue(1, $ext, \PDO::PARAM_STR);
    $sth->execute();
    $mimeType = $sth->fetchColumn();
    if (!is_string($mimeType)) {
        $app->abort(404, 'No such extension');
    }
    $filename = __DIR__ . "/repository/tidus_laugh.{$ext}";
    $expiresDate = new \DateTime();
    $expiresDate->modify('+1 day');
    $response = new BinaryFileResponse($filename);
    $response->headers->set('Content-Type', $mimeType);
    $response->setPublic();
    $response->setExpires($expiresDate);
    return $response;
})->assert('ext', '^[0-9a-z]+$');
$app->get('/manage', function () use($app) {
    $extensions = $app['db']->fetchAll('SELECT * FROM extensions ORDER BY extension ASC');
    return $app->render('manage.html.twig', ['extensions' => $extensions]);
});
$app->post('/new', function (Request $request) use($app) {
    $extension = $request->request->get('extension');
    $mimeType = $request->request->get('mime_type');
    $password = $request->request->get('password');
    foreach ([$extension, $mimeType, $password] as $input) {
        if (!is_string($input) || !strlen($input)) {
            $app->abort(403, 'Bad input');
        }