public function sendHeaders($archiveName = 'archive.zip', $contentType = 'application/zip') {
    $headerFile = null;
    $headerLine = null;
    if (!headers_sent($headerFile, $headerLine)
          or die("<p><strong>Error:</strong> Unable to send file " .
                 "$archiveName. HTML Headers have already been sent from " .
                 "<strong>$headerFile</strong> in line <strong>$headerLine" .
                 "</strong></p>")) {
      if ((ob_get_contents() === false || ob_get_contents() == '')
           or die("\n<p><strong>Error:</strong> Unable to send file " .
                  "<strong>$archiveName.epub</strong>. Output buffer " .
                  "already contains text (typically warnings or errors).</p>")) {
        header('Pragma: public');
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s T'));
        header('Expires: 0');
        header('Accept-Ranges: bytes');
        header('Connection: Keep-Alive');
        header('Content-Type: ' . $contentType);
        // Use UTF-8 filenames when not using Internet Explorer
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') > 0) {
          header('Content-Disposition: attachment; filename="' . rawurlencode($archiveName) . '"' );
        }  else  {
          header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($archiveName)
              . '; filename="' . rawurlencode($archiveName) . '"' );
        }
        header('Content-Transfer-Encoding: binary');
      }
    }
    $this->flush();
    // turn off output buffering
    @ob_end_flush();
  }
public function sendHeaders($archiveName = 'archive.zip', $contentType = 'application/zip') {
    $headerFile = null;
    $headerLine = null;
    if (!headers_sent($headerFile, $headerLine)
          or die("<p><strong>Error:</strong> Unable to send file " .
                 "$archiveName. HTML Headers have already been sent from " .
                 "<strong>$headerFile</strong> in line <strong>$headerLine" .
                 "</strong></p>")) {
      if ((ob_get_contents() === false || ob_get_contents() == '')
           or die("\n<p><strong>Error:</strong> Unable to send file " .
                  "<strong>$archiveName.epub</strong>. Output buffer " .
                  "already contains text (typically warnings or errors).</p>")) {
        header('Pragma: public');
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s T'));
        header('Expires: 0');
        header('Accept-Ranges: bytes');
        header('Connection: Keep-Alive');
        header('Content-Type: ' . $contentType);
        // Use UTF-8 filenames when not using Internet Explorer
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') > 0) {
          header('Content-Disposition: attachment; filename="' . rawurlencode($archiveName) . '"' );
        }  else  {
          header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($archiveName)
              . '; filename="' . rawurlencode($archiveName) . '"' );
        }
        header('Content-Transfer-Encoding: binary');
      }
    }
    $this->flush();
    // turn off output buffering
    @ob_end_flush();
  }
public function sendHeaders ( $ archiveName = 'archive.zip' , $ contentType = 'application/zip' ) { $ headerFile = null ; $ headerLine = null ; if ( ! headers_sent ( $ headerFile , $ headerLine ) or die ( "<p><strong>Error:</strong> Unable to send file " . "$archiveName. HTML Headers have already been sent from " . "<strong>$headerFile</strong> in line <strong>$headerLine" . "</strong></p>" ) ) { if ( ( ob_get_contents ( ) === false || ob_get_contents ( ) == '' ) or die ( "\n<p><strong>Error:</strong> Unable to send file " . "<strong>$archiveName.epub</strong>. Output buffer " . "already contains text (typically warnings or errors).</p>" ) ) { header ( 'Pragma: public' ) ; header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s T' ) ) ; header ( 'Expires: 0' ) ; header ( 'Accept-Ranges: bytes' ) ; header ( 'Connection: Keep-Alive' ) ; header ( 'Content-Type: ' . $ contentType ) ; // Use UTF-8 filenames when not using Internet Explorer if ( strpos ( $ _SERVER [ 'HTTP_USER_AGENT' ] , 'MSIE' ) > 0 ) { header ( 'Content-Disposition: attachment; filename="' . rawurlencode ( $ archiveName ) . '"' ) ; } else { header ( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode ( $ archiveName ) . '; filename="' . rawurlencode ( $ archiveName ) . '"' ) ; } header ( 'Content-Transfer-Encoding: binary' ) ; } } $ this -> flush ( ) ; // turn off output buffering @ ob_end_flush ( ) ; }
Send appropriate http headers before streaming the zip file and disable output buffering.
This method, if used, has to be called before adding anything to the zip file.

@param string $archiveName Filename of archive to be created (optional, default 'archive.zip')
@param string $contentType Content mime type to be set (optional, default 'application/zip')
Send appropriate http headers before streaming the zip file and disable output buffering . This method if used has to be called before adding anything to the zip file .