index.php 861 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. require 'vendor/mustangostang/spyc/Spyc.php';
  3. $metadata = Spyc::YAMLLoad('metadata.yml');
  4. $today = date('Ymd');
  5. $current = '';
  6. $sizeU = '';
  7. $sizeC = '';
  8. foreach($metadata as $row) {
  9. $start = $row['start'];
  10. $end = $row['end'];
  11. if ($start <= $today and $today <= $end) {
  12. $current = $row['id'];
  13. $sizeU = $row['size_uncompressed'];
  14. $sizeC = $row['size_compressed'];
  15. break;
  16. }
  17. }
  18. unset($row);
  19. $etag = $_SERVER['HTTP_IF_NONE_MATCH'];
  20. if ($etag == $current) {
  21. http_response_code(304);
  22. } else {
  23. header("ETag: $current");
  24. header('Content-Type: application/octet-stream');
  25. header('Content-Disposition: attachment; filename="timetable.db.gz"');
  26. header('Content-Length: ' . filesize("$current.db.gz"));
  27. header('X-Uncompressed-Content-Length: ' . $sizeU);
  28. readfile("$current.db.gz");
  29. }
  30. ?>