The Zip class enables the extraction of zip archives according to Wikipedia’s zip file format information (don’t you just love Wikipedia?).
This class implements the Extractor interface.
| Zip | The Zip class enables the extraction of zip archives according to Wikipedia’s zip file format information (don’t you just love Wikipedia?) |
| Variables | |
| filename | |
| fp | |
| Functions | |
| __construct | Initializes all attributes to null and can also be used to open a zipped archive. |
| open | Opens the specified zip archive for reading. |
| files | Returns an array containing all the files and folders contained within the current zip archive. |
| extract | Extracts the current zip archive to the specified location. |
| read | Reads the specified file from the current zip archive and returns the contents of the file or saves it to the specified file. |
| close | Closes the zip archive currently being read. |
| __destruct | |
| is_supported | Returns whether or not a zip archive could be extracted on the current system. |
| __construct | Initializes all attributes to null and can also be used to open a zipped archive. |
| open | Opens the specified zip archive for reading. |
| files | Returns an array containing all the files and folders contained within the current zip archive. |
| extract | Extracts the current zip archive to the specified location. |
| read | Reads the specified file from the current zip archive and returns the contents of the file or saves it to the specified file. |
| close | Closes the zip archive currently being read. |
| __destruct | |
| is_supported | Returns whether or not a zip archive could be extracted on the current system. |
public function open( $filename )
Opens the specified zip archive for reading.
| string $filename | The name of the zip archive to open. |
| bool | Returns true if the zip archive was opened successfully, false if the file does not exist or is not a valid zip archive. |
This method may also return false if extracting zip archives are not supported on this system. See Zip::is_supported for more details.
public function extract( $destination, $safe_mode = true )
Extracts the current zip archive to the specified location.
| string $destination | Where the contents of the zip archive will be extracted to. |
| bool $safe_mode | It is, of course, possible for files to have such names as ../../someImportantFile.sys which would then possibly overwrite a very important file of any kind. By setting this to true, the name of the file will have ../ and /.. removed. |
| bool | Returns true on success, false on failure. |
public function read( $filename, $destination = null )
Reads the specified file from the current zip archive and returns the contents of the file or saves it to the specified file.
| string $filename | The name of the file in the zip archive to read. |
| string $destination | The location where $filename should be saved to, if left blank the contents will be returned. |
| mixed | Returns a string containing the files contents if $destination is left empty but false if the file does not exist. If a destination is supplied, true will be returned on success and false on failure (e.g. the file does not exist). |
File names are case-sensitive!
This does not work on directories in the archives, only files can be retrieved.
If you want to retrieve a list of all the directories (and files) within a zip archive, check out Zip::files.
public function is_supported()
Returns whether or not a zip archive could be extracted on the current system.
none
| bool | Returns true if a zip archive could be extracted on the current system, false if not. |
In order for a zip archive to be extracted the Zip class requires the use of the <www.php.net/gzinflate> function which is part of the <www.php.net/zlib> extension.
private $filename
private $fp
Initializes all attributes to null and can also be used to open a zipped archive.
public function __construct( $filename = null )
Opens the specified zip archive for reading.
public function open( $filename )
Returns an array containing all the files and folders contained within the current zip archive.
public function files()
Extracts the current zip archive to the specified location.
public function extract( $destination, $safe_mode = true )
Reads the specified file from the current zip archive and returns the contents of the file or saves it to the specified file.
public function read( $filename, $destination = null )
Closes the zip archive currently being read.
public function close()
public function __destruct()
Returns whether or not a zip archive could be extracted on the current system.
public function is_supported()