diff options
| author | pabs <pabs@pablotron.org> | 2007-08-22 22:39:07 -0400 | 
|---|---|---|
| committer | pabs <pabs@pablotron.org> | 2007-08-22 22:39:07 -0400 | 
| commit | 8c37b04bacfdaaaedc736c1f949cdec0c5fa0e26 (patch) | |
| tree | dd19aa0f23ce9287a9790c1fbd2cef9ab5eb7981 /zipstream.php | |
| parent | f11b211f154ec56dc860a2b3bfadb17f2a3325dc (diff) | |
| download | zipstream-php-8c37b04bacfdaaaedc736c1f949cdec0c5fa0e26.tar.xz zipstream-php-8c37b04bacfdaaaedc736c1f949cdec0c5fa0e26.zip  | |
Added send_http_headers and constructor.
Diffstat (limited to 'zipstream.php')
| -rw-r--r-- | zipstream.php | 39 | 
1 files changed, 33 insertions, 6 deletions
diff --git a/zipstream.php b/zipstream.php index 03fb96b..6a7b374 100644 --- a/zipstream.php +++ b/zipstream.php @@ -24,6 +24,11 @@ class ZipStream {        $cdr_ofs = 0,        $ofs = 0;  +  function ZipStream($name = 'untitled.zip', $send_http_headers = false) { +    $this->output_name = $name; +    $this->need_headers = $send_http_headers;  +  } +    #    # add_file - add a file to the archive    # @@ -73,7 +78,7 @@ class ZipStream {      $this->add_to_cdr($name, $time, $crc, $zlen, $len, $full_len);      # print data -    echo $ret; +    $this->send($ret);    }    # @@ -94,12 +99,18 @@ class ZipStream {      $this->clear();    } -  function clear() { -    $this->files = array(0; -    $this->ofs = 0; -    $this->cdr_ofs = 0; -  } +  function send_http_headers($name = 'untitled.zip') { +    $headers = array( +      'Content-Type'              => 'application/x-zip', +      'Content-Disposition'       => "attachment; filename=\"{$name}\"", +      'Pragma'                    => 'public', +      'Cache-Control'             => 'public, must-revalidate', +      'Content-Transfer-Encoding' => 'binary', +    ); +    foreach ($headers as $key => $val) +      header("$key: $val"); +  }    ###################    # PRIVATE METHODS # @@ -135,6 +146,8 @@ class ZipStream {      # pack fields and append name      $ret = $this->pack_fields($fields) . $name; +    $this->send($ret); +      # increment cdr offset      $this->cdr_ofs += strlen($ret);    } @@ -162,6 +175,20 @@ class ZipStream {      $this->add_cdr_eof();    } +  function clear() { +    $this->files = array(); +    $this->ofs = 0; +    $this->cdr_ofs = 0; +  } + +  function send($str) { +    if ($this->need_headers) +      $this->send_http_headers($this->output_name); +    $this->need_headers = false; + +    echo $str; +  } +    function pack_fields($fields) {      # populate format string and argument list      list ($pack_fmt, $args) = array('', array());  | 
