1
0

location_photo.php 746 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. if(!empty($id)) {
  3. $file = LocationFile::get($id);
  4. if(!$file) throw new Exception("Photo not found.");
  5. if($file->location_id != $location_id) throw new Exception("Photo not found.");
  6. $location = Location::get($location_id);
  7. }
  8. else {
  9. $location = Location::get($location_id);
  10. if(!$location) throw new Exception("Location not found.");
  11. $photo = LocationFile::queryOne([
  12. "location_id" => $location->id,
  13. "type" => LocationFile::TYPE_PHOTO
  14. ]);
  15. if(!$photo) {
  16. header("Content-Type: image/png");
  17. readfile("public/img/no_image_4_3.png");
  18. exit;
  19. }
  20. $id = $photo->id;
  21. }
  22. $path = $location->getDirectory() . "/$id.jpg";
  23. if(!file_exists($path)) HTTP::redirect("/img/blank.png");
  24. header("Content-Type: image/jpeg");
  25. readfile($path);