1
0

practice_file.php 648 B

12345678910111213141516171819202122232425
  1. <?php
  2. $template = Template::get($id);
  3. if(!$template) throw new Exception(__("Practice form not found."));
  4. $tests = $_SESSION["practice_tests"];
  5. $test = $tests[$id] ?? false;
  6. if(!$test) throw new Exception(__("Practice test not found."));
  7. if(!Core::$user->canAccessPractice()) {
  8. if(Core::$user->id != $test->tester_id) throw new Exception(__("You do not have permission to access this resource."));
  9. }
  10. $directory = $test->getDirectory();
  11. $path = $directory . "/" . $name . ".jpg";
  12. if(file_exists($path)) {
  13. header("Content-Type: image/jpeg");
  14. readfile($path);
  15. }
  16. else {
  17. header("Content-Type: image/png");
  18. readfile("public/img/blank.png");
  19. }