test_file.php 660 B

123456789101112131415161718192021222324252627
  1. <?php
  2. $test = Test::get($id);
  3. if(!$test) throw new Exception(__("Test not found."));
  4. if(Core::$user->level < User::LEVEL_ADMIN) {
  5. if(Core::$user->id != $test->tester_id) throw new Exception(__("You do not have permission to access this resource."));
  6. }
  7. $directory = $test->getDirectory();
  8. $path_jpg = $directory . "/" . $name . ".jpg";
  9. $path_pdf = $directory . "/" . $name . ".pdf";
  10. if(file_exists($path_jpg)) {
  11. header("Content-Type: image/jpeg");
  12. readfile($path_jpg);
  13. }
  14. else if(file_exists($path_pdf)) {
  15. header("Content-Type: application/pdf");
  16. readfile($path_pdf);
  17. }
  18. else {
  19. header("Content-Type: image/png");
  20. readfile("public/img/blank.png");
  21. }
  22. ?>