Esempio n. 1
0
 /**
  * Constructor. Initializes ZipStreamer object for immediate usage.
  * @param array $options Optional, ZipStreamer and zip file options as key/value pairs.
  *                       Valid options are:
  *                       * outstream: stream the zip file is output to (default: stdout)
  *                       * zip64: enabled/disable zip64 support (default: True)
  *                       * compress: int, compression method (one of COMPR::STORE,
  *                                   COMPR::DEFLATE, default COMPR::STORE)
  *                                   can be overridden for single files
  *                       * level: int, compression level (one of COMPR::NORMAL,
  *                                COMPR::MAXIMUM, COMPR::SUPERFAST, default COMPR::NORMAL)
  */
 function __construct($options = NULL)
 {
     $defaultOptions = array('outstream' => NULL, 'zip64' => True, 'compress' => COMPR::STORE, 'level' => COMPR::NORMAL);
     if (is_null($options)) {
         $options = array();
     }
     $options = array_merge($defaultOptions, $options);
     if ($options['outstream']) {
         $this->outstream = $options['outstream'];
     } else {
         $this->outstream = fopen('php://output', 'w');
     }
     $this->zip64 = $options['zip64'];
     $this->compress = $options['compress'];
     $this->level = $options['level'];
     $this->validateCompressionOptions($this->compress, $this->level);
     //TODO: is this advisable/necessary?
     if (ini_get('zlib.output_compression')) {
         ini_set('zlib.output_compression', 'Off');
     }
     // initialize default external file attributes
     $this->extFileAttrFile = UNIX::getExtFileAttr(UNIX::S_IFREG | UNIX::S_IRUSR | UNIX::S_IWUSR | UNIX::S_IRGRP | UNIX::S_IROTH);
     $this->extFileAttrDir = UNIX::getExtFileAttr(UNIX::S_IFDIR | UNIX::S_IRWXU | UNIX::S_IRGRP | UNIX::S_IXGRP | UNIX::S_IROTH | UNIX::S_IXOTH) | DOS::getExtFileAttr(DOS::DIR);
     $this->offset = Count64::construct(0, !$this->zip64);
 }
Esempio n. 2
0
 /**
  * Constructor.
  *
  * @param bool   $sendHeaders Send suitable headers to the HTTP client (assumes nothing was sent yet)
  * @param string $archiveName Name to send to the HTTP client. Optional, defaults to "archive.zip".
  * @param string $contentType Content mime type. Optional, defaults to "application/zip".
  */
 function __construct($sendHeaders = false, $archiveName = 'archive.zip', $contentType = 'application/zip')
 {
     //TODO: is this advisable/necessary?
     if (ini_get('zlib.output_compression')) {
         ini_set('zlib.output_compression', 'Off');
     }
     if ($sendHeaders) {
         $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);
                 header('Content-Disposition: attachment; filename="' . $archiveName . '";');
                 header('Content-Transfer-Encoding: binary');
             }
         }
         flush();
         // turn off output buffering
         ob_end_flush();
     }
     // initialize default external file attributes
     $this->extFileAttrFile = UNIX::getExtFileAttr(UNIX::S_IFREG | UNIX::S_IRUSR | UNIX::S_IXUSR | UNIX::S_IRGRP | UNIX::S_IROTH);
     $this->extFileAttrDir = UNIX::getExtFileAttr(UNIX::S_IFDIR | UNIX::S_IRWXU | UNIX::S_IRGRP | UNIX::S_IXGRP | UNIX::S_IROTH | UNIX::S_IXOTH) | DOS::getExtFileAttr(DOS::DIR);
     $this->offset = Count64::construct(0);
 }