Http.php 674 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App;
  3. class Http {
  4. public static function redirect(string $url, int $response_code = 303): void {
  5. http_response_code($response_code);
  6. header("Location: $url");
  7. exit();
  8. }
  9. public static function referer(): ?string {
  10. return $_SERVER["HTTP_REFERER"] ?? null;
  11. }
  12. public static function sendDownloadHeaders(string $filename, string $content_type): void {
  13. header("Content-Type: $content_type");
  14. header("Content-Disposition: attachment; filename=\"$filename\"");
  15. }
  16. public static function downloadFile(string $path, string $filename, string $content_type): void {
  17. self::sendDownloadHeaders($filename, $content_type);
  18. readfile($path);
  19. }
  20. }