Пример #1
0
 public function fileDelete($id)
 {
     $file = $this->em->getRepository('Uppu3\\Entity\\File')->findOneById($id);
     $filePath = \Uppu3\Helper\FormatHelper::formatUploadLink($file->getId(), $file->getName());
     if (in_array($file->getExtension(), $this->pictures)) {
         $fileResizePath = \Uppu3\Helper\FormatHelper::formatUploadResizeLink($file->getId(), $file->getName());
         unlink($fileResizePath);
     }
     unlink($filePath);
     $this->em->remove($file);
     $this->em->flush();
     echo "all is done";
     die;
 }
Пример #2
0
    $file = $app->em->find('Uppu3\\Entity\\File', $id);
    $user = $app->em->getRepository('Uppu3\\Entity\\User')->findOneById($file->getUploadedBy());
    if (!$file) {
        $app->notFound();
    }
    $helper = new FormatHelper();
    $comments = $app->em->getRepository('Uppu3\\Entity\\Comment')->findBy(array('fileId' => $id), array('path' => 'ASC'));
    $app->render('view.html', array('file' => $file, 'user' => $user, 'helper' => $helper, 'comments' => $comments));
});
$app->get('/comment/:id/', function ($id) use($app) {
    $comment = $app->em->find('Uppu3\\Entity\\Comment', $id);
    echo $comment->getComment();
});
$app->get('/download/:id/:name', function ($id, $name) use($app) {
    $file = $app->em->find('Uppu3\\Entity\\File', $id);
    $name = FormatHelper::formatDownloadFile($id, $file->getName());
    if (file_exists($name)) {
        header("X-Sendfile:" . realpath(dirname(__FILE__)) . '/' . $name);
        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment");
        return;
    } else {
        $app->notFound();
    }
});
$app->get('/users/', 'checkAuthorization', function () use($app) {
    $page = 'users';
    $users = $app->em->getRepository('Uppu3\\Entity\\User')->findBy([], ['created' => 'DESC']);
    $filesCount = $app->em->createQuery('SELECT IDENTITY(u.uploadedBy), count(u.uploadedBy) FROM Uppu3\\Entity\\File u GROUP BY u.uploadedBy');
    $filesCount = $filesCount->getArrayResult();
    $list = [];