public function __toString()
 {
     $this->zipCommentLength = ZipUtils::bin_strlen($this->zipComment);
     $eocd = AbstractZipHeader::ZIP_END_OF_CENTRAL_DIRECTORY;
     $eocd .= pack("vvvv", $this->thisDisk, $this->firstCDDisk, $this->cdrCount1, $this->cdrCount2);
     $eocd .= pack("VVv", $this->cdrLength, $this->cdrStart, $this->zipCommentLength);
     if ($this->zipCommentLength > 0) {
         $eocd .= $this->zipComment;
     } else {
         $eocd .= AbstractZipHeader::NULL_WORD;
     }
     return $eocd;
 }
 public function getCentralDirectoryHeader()
 {
     $ef = '';
     foreach ($this->extraFieldsArray as $value) {
         /* @var $value AbstractExtraField */
         $ef .= $value->getCentralField();
     }
     $cd = AbstractZipHeader::ZIP_CENTRAL_FILE_HEADER . $this->versionMadeBy . $this->versionNeeded;
     $cd .= pack("vv", $this->gpFlags, $this->gzType);
     $cd .= $this->dosTime;
     $cd .= pack("VVV", $this->fileCRC32, $this->gzLength, $this->dataLength);
     $cd .= pack("v", ZipUtils::bin_strlen($this->path));
     $cd .= pack("v", ZipUtils::bin_strlen($ef));
     $cd .= pack("v", ZipUtils::bin_strlen($this->comment));
     $cd .= $this->discNumberStart . $this->internalFileAttributes . $this->externalFileAttributes;
     $cd .= pack("V", $this->offset);
     $cd .= $this->path;
     $cd .= $ef;
     $cd .= $this->comment;
     return $cd;
 }
 /**
  *
  * @author A. Grandt <*****@*****.**>
  * @author Greg Kappatos
  *
  * @return string The full path to a temporary file.
  */
 public static function getTemporaryFile()
 {
     if (is_callable(self::$temp)) {
         $file = @call_user_func(self::$temp);
         if (is_string($file) && ZipUtils::bin_strlen($file) && is_writable($file)) {
             return $file;
         }
     }
     $dir = is_string(self::$temp) && ZipUtils::bin_strlen(self::$temp) ? self::$temp : sys_get_temp_dir();
     if (is_dir($dir) === false) {
         $dir = ini_get('upload_tmp_dir');
     }
     if (is_dir($dir) === false) {
         $dir = ini_get('upload_tmp_dir');
     }
     return tempnam($dir, __NAMESPACE__);
 }
示例#4
0
 /**
  * Build the base standard response headers, and ensure the content can be streamed.
  *
  * @author A. Grandt <*****@*****.**>
  *
  * @param String $fileName The name of the Zip archive, in ISO-8859-1 (or ASCII) encoding, ie. "archive.zip". Optional, defaults to null, which means that no ISO-8859-1 encoded file name will be specified.
  * @param String $contentType Content mime type. Optional, defaults to "application/zip".
  * @param String $utf8FileName The name of the Zip archive, in UTF-8 encoding. Optional, defaults to null, which means that no UTF-8 encoded file name will be specified.
  * @param bool   $inline Use Content-Disposition with "inline" instead of "attached". Optional, defaults to false.
  *
  * @return bool Always returns true (for backward compatibility).
  * 
  * @throws \PHPZip\Zip\Exception\BufferNotEmpty, HeadersSent In case of errors
  */
 protected function buildResponseHeader($fileName = null, $contentType = self::CONTENT_TYPE, $utf8FileName = null, $inline = false)
 {
     $ob = null;
     $headerFile = null;
     $headerLine = null;
     $zlibConfig = 'zlib.output_compression';
     $ob = ob_get_contents();
     if ($ob !== false && ZipUtils::bin_strlen($ob)) {
         $this->_throwException(new BufferNotEmpty(array('outputBuffer' => $ob, 'fileName' => $fileName)));
     }
     if (headers_sent($headerFile, $headerLine)) {
         $this->_throwException(new HeadersSent(array('headerFile' => $headerFile, 'headerLine' => $headerLine, 'fileName' => $fileName)));
     }
     if (@ini_get($zlibConfig)) {
         @ini_set($zlibConfig, 'Off');
     }
     $cd = 'Content-Disposition: ' . ($inline ? 'inline' : 'attached');
     if ($fileName) {
         $cd .= '; filename="' . $fileName . '"';
     }
     if ($utf8FileName) {
         $cd .= "; filename*=UTF-8''" . rawurlencode($utf8FileName);
     }
     header('Pragma: public');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s T'));
     header('Expires: 0');
     header('Accept-Ranges: bytes');
     header('Connection: close');
     header('Content-Type: ' . $contentType);
     header($cd);
     return true;
 }
 /**
  * @return string The version of the field for the Central Header.
  */
 public function getCentralField()
 {
     return parent::HEADER_UNICODE_COMMENT . pack('vV', ZipUtils::bin_strlen($this->utf8Data) + 5, $this->CRC32) . $this->version . $this->utf8Data;
 }
示例#6
0
 /**
  * Return the current size of the archive
  *
  * @author A. Grandt <*****@*****.**>
  *
  * @return int Size of the archive
  */
 public function getArchiveSize()
 {
     if (!is_resource($this->_zipFile)) {
         return ZipUtils::bin_strlen($this->_zipData);
     }
     $stat = fstat($this->_zipFile);
     return $stat['size'];
 }
 public static function encodeField($header, $data)
 {
     if ($header != null) {
         return $header . pack('v', ZipUtils::bin_strlen($data)) . $data;
     }
     return '';
 }
 /**
  * @return string The version of the field for the Central Header.
  */
 public function getCentralField()
 {
     $ts = $this->isModTimeSet ? pack('V', $this->modTime) : '';
     $flags = 0;
     ZipUtils::setBit($flags, 0, $this->isModTimeSet);
     ZipUtils::setBit($flags, 1, $this->isAcTimeSet);
     ZipUtils::setBit($flags, 2, $this->isCrTimeSet);
     return parent::HEADER_EXTENDED_TIMESTAMP . pack('vc', 1 + ZipUtils::bin_strlen($ts), $flags) . $ts;
 }