Constants

VERSION

VERSION = 1.4

ZIP_LOCAL_FILE_HEADER

ZIP_LOCAL_FILE_HEADER = "PK\x03\x04"

ZIP_CENTRAL_FILE_HEADER

ZIP_CENTRAL_FILE_HEADER = "PK\x01\x02"

ZIP_END_OF_CENTRAL_DIRECTORY

ZIP_END_OF_CENTRAL_DIRECTORY = "PK\x05\x06\x00\x00\x00\x00"

EXT_FILE_ATTR_DIR

EXT_FILE_ATTR_DIR = "\x10\x00\xffA"

EXT_FILE_ATTR_FILE

EXT_FILE_ATTR_FILE = "\x00\x00\xff\x81"

ATTR_VERSION_TO_EXTRACT

ATTR_VERSION_TO_EXTRACT = "\x14\x00"

ATTR_MADE_BY_VERSION

ATTR_MADE_BY_VERSION = "\x1e\x03"

Properties

$zipMemoryThreshold

$zipMemoryThreshold

$zipComment

$zipComment

$cdRec

$cdRec

$offset

$offset

$isFinalized

$isFinalized

$addExtraField

$addExtraField

$streamChunkSize

$streamChunkSize

$streamFilePath

$streamFilePath

$streamTimeStamp

$streamTimeStamp

$streamComment

$streamComment

$streamFile

$streamFile

$streamData

$streamData

$streamFileLength

$streamFileLength

Methods

__construct()

__construct(string  $archiveName = "", string  $contentType = "application/zip") : mixed

Constructor.

Parameters

string $archiveName

Name to send to the HTTP client.

string $contentType

Content mime type. Optional, defaults to "application/zip".

Returns

mixed —

__destruct()

__destruct() : mixed

Returns

mixed —

setExtraField()

setExtraField(bool  $setExtraField = TRUE) : mixed

Extra fields on the Zip directory records are Unix time codes needed for compatibility on the default Mac zip archive tool.

These are enabled as default, as they do no harm elsewhere and only add 26 bytes per file added.

Parameters

bool $setExtraField

TRUE (default) will enable adding of extra fields, anything else will disable it.

Returns

mixed —

setComment()

setComment(string  $newComment = null) : bool

Set Zip archive comment.

Parameters

string $newComment

New comment. null to clear.

Returns

bool —

$success

addDirectory()

addDirectory(string  $directoryPath, int  $timestamp, string  $fileComment = null) : bool

Add an empty directory entry to the zip archive.

Basically this is only used if an empty directory is added.

Parameters

string $directoryPath

Directory Path and name to be added to the archive.

int $timestamp

(Optional) Timestamp for the added directory, if omitted or set to 0, the current time will be used.

string $fileComment

(Optional) Comment to be added to the archive for this directory. To use fileComment, timestamp must be given.

Returns

bool —

$success

addFile()

addFile(string  $data, string  $filePath, int  $timestamp, string  $fileComment = null, bool  $compress = TRUE) : bool

Add a file to the archive at the specified location and file name.

Parameters

string $data

File data.

string $filePath

Filepath and name to be used in the archive.

int $timestamp

(Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.

string $fileComment

(Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.

bool $compress

(Optional) Compress file, if set to FALSE the file will only be stored. Default TRUE.

Returns

bool —

$success

addDirectoryContent()

addDirectoryContent(string  $realPath, string  $zipPath, bool  $recursive = TRUE, bool  $followSymlinks = TRUE, array  $addedFiles = array()) : mixed

Add the content to a directory.

Parameters

string $realPath

Path on the file system.

string $zipPath

Filepath and name to be used in the archive.

bool $recursive

Add content recursively, default is TRUE.

bool $followSymlinks

Follow and add symbolic links, if they are accessible, default is TRUE.

array $addedFiles

Reference to the added files, this is used to prevent duplicates, efault is an empty array. If you start the function by parsing an array, the array will be populated with the realPath and zipPath kay/value pairs added to the archive by the function.

Returns

mixed —

addLargeFile()

addLargeFile(string  $dataFile, string  $filePath, int  $timestamp, string  $fileComment = null) : bool

Add a file to the archive at the specified location and file name.

Parameters

string $dataFile

File name/path.

string $filePath

Filepath and name to be used in the archive.

int $timestamp

(Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.

string $fileComment

(Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.

Returns

bool —

$success

openStream()

openStream(string  $filePath, int  $timestamp, string  $fileComment = null) : bool

Create a stream to be used for large entries.

Parameters

string $filePath

Filepath and name to be used in the archive.

int $timestamp

(Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.

string $fileComment

(Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.

Returns

bool —

$success

addStreamData()

addStreamData(string  $data) : mixed

Add data to the open stream.

Parameters

string $data

Returns

mixed —

closeStream()

closeStream() : bool

Close the current stream.

Returns

bool —

$success

finalize()

finalize() : bool

Close the archive.

A closed archive can no longer have new files added to it.

Returns

bool —

$success

pathJoin()

pathJoin(string  $dir, string  $file) : mixed

Join $file to $dir path, and clean up any excess slashes.

Parameters

string $dir
string $file

Returns

mixed —

getRelativePath()

getRelativePath(string  $path) : string

Clean up a path, removing any unnecessary elements such as /./, // or redundant ../ segments.

If the path starts with a "/", it is deemed an absolute path and any /../ in the beginning is stripped off. The returned path will not end in a "/".

Parameters

string $path

The path to clean up

Returns

string —

the clean path

processFile()

processFile(mixed  $dataFile, mixed  $filePath, mixed  $timestamp, mixed  $fileComment = null, mixed  $compress = TRUE) : mixed

Parameters

mixed $dataFile
mixed $filePath
mixed $timestamp
mixed $fileComment
mixed $compress

Returns

mixed —

getDosTime()

getDosTime(int  $timestamp) : mixed

Calculate the 2 byte dostime used in the zip entries.

Parameters

int $timestamp

Returns

mixed —

buildZipEntry()

buildZipEntry(string  $filePath, string  $fileComment, string  $gpFlags, string  $gzType, int  $timestamp, string  $fileCRC32, int  $gzLength, int  $dataLength, int  $extFileAttr) : mixed

Build the Zip file structures

Parameters

string $filePath
string $fileComment
string $gpFlags
string $gzType
int $timestamp
string $fileCRC32
int $gzLength
int $dataLength
int $extFileAttr

Use self::EXT_FILE_ATTR_FILE for files, self::EXT_FILE_ATTR_DIR for Directories.

Returns

mixed —