Property | Type | Description | |
---|---|---|---|
$cdr_ofs | integer | ||
$files | array | ||
$ofs | integer | ||
$opt | array | Global Options |
Property | Type | Description | |
---|---|---|---|
$need_headers | boolean | ||
$output_name | null | String |
Method | Description | |
---|---|---|
__construct ( String $name = null, array $opt = [] ) | Create a new ZipStream object. | |
addFile ( String $name, String $data, array $opt = [] ) | addFile | |
addFileFromPath ( String $name, String $path, array $opt = [] ) : void | addFileFromPath | |
addFileFromStream ( String $name, Resource $stream, array $opt = [] ) : void | addFile_from_stream | |
finish ( ) : void | finish |
Method | Description | |
---|---|---|
addCdr ( array $opt = null ) : void | Add CDR (Central Directory Record) footer. | |
addCdrEof ( array $opt = null ) : void | Send CDR EOF (Central Directory Record End-of-File) record. | |
addCdrFile ( array $args ) : void | Send CDR record for specified file. | |
addDataDescriptorHeader ( integer $len, integer $zlen, String $crc ) : integer | ||
addFileHeader ( String $name, Array &$opt, integer $meth, string $crc, integer $zlen, integer $len, Hex $genb ) : integer | Create and send zip header for this file. | |
addLargeFile ( String $name, String $path, array $opt = [] ) : void | Add a large file from the given path. | |
clear ( ) : void | Clear all internal variables. Note that the stream object is not usable after this. | |
dostime ( integer $when ) : integer | Convert a UNIX timestamp to a DOS timestamp. | |
isLargeFile ( string $path ) : boolean | Is this file larger than large_file_size? | |
packFields ( array $fields ) : string | Create a format string and argument list for pack(), then call pack() and return the result. | |
send ( String $str ) : void | Send string, sending HTTP headers if necessary. | |
sendHttpHeaders ( ) : void | Send HTTP headers for this stream. |
Method | Description | |
---|---|---|
addToCdr ( String $name, Array $opt, integer $meth, string $crc, integer $zlen, integer $len, integer $rec_len, Hex $genb ) : integer | Save file attributes for trailing CDR record. |
public __construct ( String $name = null, array $opt = [] ) | ||
$name | String | - Name of output file (optional). |
$opt | array | - Hash of archive options (optional, see "Archive Options" below). Archive Options: comment - Comment for this archive. content_type - HTTP Content-Type. Defaults to 'application/x-zip'. content_disposition - HTTP Content-Disposition. Defaults to 'attachment; filename=\"FILENAME\"', where FILENAME is the specified filename. large_file_size - Size, in bytes, of the largest file to try and load into memory (used by addFileFromPath()). Large files may also be compressed differently; see the 'large_file_method' option. large_file_method - How to handle large files. Legal values are 'store' (the default), or 'deflate'. Store sends the file raw and is significantly faster, while 'deflate' compresses the file and is much, much slower. Note that deflate must compress the file twice and extremely slow. sendHttpHeaders - Boolean indicating whether or not to send the HTTP headers for this file. Note that content_type and content_disposition do nothing if you are not sending HTTP headers. Large File Support: By default, the method addFileFromPath() will send send files larger than 20 megabytes along raw rather than attempting to compress them. You can change both the maximum size and the compression behavior using the large_file_* options above, with the following caveats: * For "small" files (e.g. files smaller than large_file_size), the memory use can be up to twice that of the actual file. In other words, adding a 10 megabyte file to the archive could potentially occupty 20 megabytes of memory. * Enabling compression on large files (e.g. files larger than large_file_size) is extremely slow, because ZipStream has to pass over the large file once to calculate header information, and then again to compress and send the actual data. Examples: // create a new zip file named 'foo.zip' $zip = new ZipStream('foo.zip'); // create a new zip file named 'bar.zip' with a comment $zip = new ZipStream('bar.zip', array( 'comment' => 'this is a comment for the zip file.', )); Notes: If you do not set a filename, then this library _DOES NOT_ send HTTP headers by default. This behavior is to allow software to send its own headers (including the filename), and still use this library. |
protected addCdrFile ( array $args ) : void | ||
$args | array | |
return | void |
public addFile ( String $name, String $data, array $opt = [] ) | ||
$name | String | - path of file in archive (including directory). @param String $data - contents of file @param array $opt - Hash of options for file (optional, see "File Options" below). File Options: time - Last-modified timestamp (seconds since the epoch) of this file. Defaults to the current time. comment - Comment related to this file. Examples: // add a file named 'foo.txt' $data = file_get_contents('foo.txt'); $zip->addFile('foo.txt', $data); // add a file named 'bar.jpg' with a comment and a last-modified // time of two hours ago $data = file_get_contents('bar.jpg'); $zip->addFile('bar.jpg', $data, array( 'time' => time() - 2 * 3600, 'comment' => 'this is a comment about bar.jpg', )); |
$data | String | |
$opt | array |
public addFileFromPath ( String $name, String $path, array $opt = [] ) : void | ||
$name | String | - name of file in archive (including directory path). @param String $path - path to file on disk (note: paths should be encoded using UNIX-style forward slashes -- e.g '/path/to/some/file'). @param array $opt - Hash of options for file (optional, see "File Options" below). File Options: time - Last-modified timestamp (seconds since the epoch) of this file. Defaults to the current time. comment - Comment related to this file. Examples: // add a file named 'foo.txt' from the local file '/tmp/foo.txt' $zip->addFileFromPath('foo.txt', '/tmp/foo.txt'); // add a file named 'bigfile.rar' from the local file // '/usr/share/bigfile.rar' with a comment and a last-modified // time of two hours ago $path = '/usr/share/bigfile.rar'; $zip->addFileFromPath('bigfile.rar', $path, array( 'time' => time() - 2 * 3600, 'comment' => 'this is a comment about bar.jpg', )); |
$path | String | |
$opt | array | |
return | void |
public addFileFromStream ( String $name, Resource $stream, array $opt = [] ) : void | ||
$name | String | - path of file in archive (including directory). |
$stream | Resource | - contents of file as a stream resource |
$opt | array | - Hash of options for file (optional, see "File Options" below). File Options: time - Last-modified timestamp (seconds since the epoch) of this file. Defaults to the current time. comment - Comment related to this file. Examples: // create a temporary file stream and write text to it $fp = tmpfile(); fwrite($fp, 'The quick brown fox jumped over the lazy dog.'); // add a file named 'streamfile.txt' from the content of the stream $x->addFile_from_stream('streamfile.txt', $fp); |
return | void |
protected addLargeFile ( String $name, String $path, array $opt = [] ) : void | ||
$name | String | |
$path | String | |
$opt | array | |
return | void |
protected isLargeFile ( string $path ) : boolean | ||
$path | string | |
return | boolean |
protected packFields ( array $fields ) : string | ||
$fields | array | |
return | string |
protected sendHttpHeaders ( ) : void | ||
return | void |