Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Download.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace SCF\Additionals;
  3. class Download
  4. {
  5. /**
  6. * @var string
  7. */
  8. private $absolutePath;
  9. /**
  10. * @var string
  11. */
  12. private $fileName;
  13. public function __construct()
  14. {
  15. }
  16. /**
  17. * @param string $fileName
  18. */
  19. public function setFileName($fileName)
  20. {
  21. $this->fileName = $fileName;
  22. }
  23. /**
  24. * @return string
  25. */
  26. public function getFileName()
  27. {
  28. return $this->fileName;
  29. }
  30. /**
  31. * @return string
  32. */
  33. public function getAbsolutePath()
  34. {
  35. return $this->absolutePath;
  36. }
  37. /**
  38. * @param string $absolutePath
  39. */
  40. public function setAbsolutePath($absolutePath)
  41. {
  42. $this->absolutePath = $absolutePath;
  43. }
  44. /**
  45. * Download Control. Starts Downloads with the selected File in $tmpFile
  46. * Absolute Path must be given!
  47. */
  48. public function startDownloadFile()
  49. {
  50. $tmpPath = $this->getAbsolutePath();
  51. $tmpFile = $this->getFileName();
  52. $fh = fopen($tmpPath . $tmpFile, "r");
  53. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  54. header('Content-Description: File Transfer');
  55. header('Content-Type: application/octed-stream');
  56. header('Content-Length: ' . @filesize($tmpPath . $tmpFile));
  57. header("Content-Disposition: attachment; filename=" . $tmpFile);
  58. header("Content-Transfer-Encoding: binary");
  59. while (true) {
  60. echo fgets($fh, 4096);
  61. if (feof($fh)) break;
  62. if (connection_status() != 0) break;
  63. }
  64. fclose($fh);
  65. }
  66. }