예제 #1
0
 public function fileDelete($id)
 {
     $file = $this->em->getRepository('Uppu4\\Entity\\File')->findOneById($id);
     $filePath = FormatHelper::formatUploadLink($file->getId(), $file->getName());
     $this->em->remove($file);
     $this->em->flush();
     if (in_array($file->getExtension(), $this->pictures)) {
         $fileResizePath = FormatHelper::formatUploadResizeLink($file->getId(), $file->getName());
         unlink($fileResizePath);
     }
     unlink($filePath);
 }
예제 #2
0
파일: index.php 프로젝트: V3N0m21/Uppu4
        $user = $app->em->find('Uppu4\\Entity\\User', $app->request->params('userId'));
        $validation = new \Uppu4\Helper\DataValidator();
        $commentHelper = new CommentHelper($app->em);
        $comment = $commentHelper->createComment($app->request->params('comment'), $parent, $file, $user);
        $errors = $validation->validateComment($comment);
        if (empty($errors)) {
            $commentHelper->commentSave($comment);
        }
        $comments = $commentHelper->getAllComments($file->getId());
        $app->render('comments.html', array('comments' => $comments));
    }
    if ($app->request->isGet()) {
        $file = $app->em->find('Uppu4\\Entity\\File', $id);
        $commentHelper = new CommentHelper($app->em);
        $comments = $commentHelper->getAllComments($file->getId());
        $app->render('comments.html', array('comments' => $comments));
    }
})->via('GET', 'POST');
$app->get('/download/:id/:name', function ($id, $name) use($app) {
    $file = $app->em->find('Uppu4\\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->run();