test_file.php 493 B

12345678910111213141516171819202122
  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 = $directory . "/" . $name . ".jpg";
  9. if(file_exists($path)) {
  10. header("Content-Type: image/jpeg");
  11. readfile($path);
  12. }
  13. else {
  14. header("Content-Type: image/png");
  15. readfile("public/img/blank.png");
  16. }
  17. ?>