예제 #1
0
파일: main.php 프로젝트: SlimBN/UploadIt
        throw new Exception('Permission denied');
    }
    $app['zadania_service']->delete($id);
    return new RedirectResponse($app['url_generator']->generate('home'));
})->before($checkUser)->bind('zadanie.delete')->convert('id', function ($id) {
    return (int) $id;
});
/**
 * Stahovanie zadani
 */
$app->get('/zadanie/{id}/zip', function (Silex\Application $app, $id) {
    error_reporting(0);
    $filelist = $app['zadania_service']->getFileList($id);
    $notelist = $app['zadania_service']->getNotes($id);
    $stream = function () use($filelist, $notelist, $id) {
        $zip = new ZipStream('zadanie_' . $id . '.zip');
        foreach ($notelist as $note) {
            if (empty($note['poznamka'])) {
                continue;
            }
            $zip->add_file('zadanie_' . $id . '/' . $note['login'] . '/poznamka.txt', $note['poznamka']);
        }
        foreach ($filelist as $subor) {
            $zip->add_file_from_path('zadanie_' . $id . '/' . $subor['login'] . '/' . $subor['nazov'], __DIR__ . '/uploads/' . $subor['cesta']);
        }
        $zip->finish();
    };
    return $app->stream($stream, 200, array('Content-Type' => 'application/zip'));
})->before($checkUser)->bind('zadanie.zip')->convert('id', function ($id) {
    return (int) $id;
});