PHP 25
Download Guest on 6th October 2020 05:25:21 PM
  1. <?php
  2.  
  3. class Download
  4. {
  5.  
  6.     // push download of a file //
  7.     public static function push($fullpath, $filename, $contentType = "application/image/png")
  8.     {
  9.  
  10.         ## Redirect output to a client’s web browser ##
  11.        header('Content-Type: ' . $contentType);
  12.         header('Content-Disposition: attachment;filename="' . $filename . '"');
  13.  
  14.         ## cach control ##
  15.        header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
  16.         header('Cache-Control: no-cache, max-age=0');
  17.         header('Cache-Control: no-cache, max-age=0, stale-while-revalidate=300');
  18.         ## cach control ##
  19.  
  20.         ## If you're serving to IE over SSL, then the following may be needed
  21.        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');                ## Date in the past.
  22.        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');   ## always modified
  23.        header('Pragma: no-cache');                                      ## HTTP/1.0
  24.  
  25.         ## source and distination streams ##
  26.        $sourceStream = fopen($fullpath, 'rb');
  27.         $distStream   = fopen('php://output', 'wb');
  28.         ## source and distination streams ##
  29.  
  30.         ## push download as a stream ##
  31.        stream_copy_to_stream($sourceStream, $distStream);
  32.         ob_flush();
  33.         flush();
  34.         ## push download as a stream ##
  35.  
  36.     }
  37. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.