KXStudio Website https://kx.studio/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

download.php 1.2KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. if (file_exists("/var/www/kxstudio/paste/")) {
  3. $base_dir = "/var/www/kxstudio/paste/";
  4. } else {
  5. $base_dir = "/home/groups/k/kx/kxstudio/htdocs/paste/";
  6. }
  7. function downloadFile($fullPath) {
  8. // Must be fresh start
  9. if (headers_sent()) {
  10. die('Headers Sent');
  11. }
  12. // Required for some browsers
  13. if (ini_get('zlib.output_compression')) {
  14. ini_set('zlib.output_compression', 'Off');
  15. }
  16. $fsize = filesize($fullPath);
  17. header("Pragma: public"); // required
  18. header("Expires: 0");
  19. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  20. header("Cache-Control: private", false); // required for certain browsers
  21. header("Content-Type: application/force-download");
  22. header("Content-Disposition: attachment; filename=\"".basename($fullPath)."\";" );
  23. header("Content-Transfer-Encoding: binary");
  24. header("Content-Length: " . $fsize);
  25. ob_clean();
  26. flush();
  27. readfile($fullPath);
  28. }
  29. if (! empty($_GET["id"])) {
  30. $paste_id = htmlspecialchars($_GET["id"]);
  31. $paste_file = $base_dir . "repo/" . $paste_id;
  32. if (! file_exists($paste_file)) {
  33. die("File does not exist");
  34. }
  35. downloadFile($paste_file);
  36. }
  37. ?>