PHP Modules Tutorials - Herong's Tutorial Examples
∟Zip Module - Managing ZIP Archive Files
This chapter provides tutorial examples and notes on Zip module for managing ZIP archive files. Topics include introduction of ZipArchive class; creating new ZIP archive; extracting files from ZIP archive; creating directory structure inside ZIP archive; creating ZIP archive in a temporary file with dynamic data.
The ZipArchive Class
Create New ZIP Archive
Extract Files from ZIP Archive
Create ZIP Archive with Directory
Create ZIP Archive for Download
Takeaways:
- Use ZipArchive class to manage ZIP archives with PHP scripts.
- Use "$zip = new ZipArchive;" to create an instance of ZipArchive class.
- Use "$zip->open($zip_path_name, ZipArchive::CREATE);" to create a ZIP archive.
- Use "$zip->addFile($file);" to add a file to the ZIP archive.
- Use "$zip->extractTo($destination, $file);" to extract a file from the ZIP archive.
- Use "$zip->addEmptyDir($dir_path);" to create a directory inside the ZIP archive.
- Use "$zip->addFile($file, $dir_path);" to add a file to the given directory inside the ZIP archive.
- Use "$tmpDir = sys_get_temp_dir();" to access the system temporary directory.
- Use "$tmpFile = tempnam($tmpDir, $prefix);" to get a temporary file name.
- Use "$zip->open($tmpFile, ZipArchive::CREATE);" to create a ZIP archive in a temporary file.
- Use "$zip->addFromString($fileName, $data);" to add dynamic data as file inside the ZIP archive.
Table of Contents
About This Book
Introduction and Installation of PHP
Managing PHP Engine and Modules on macOS
Managing PHP Engine and Modules on CentOS
cURL Module - Client for URL
DOM Module - Parsing HTML Documents
GD Module - Manipulating Images and Pictures
MySQLi Module - Accessing MySQL Server
OpenSSL Module - Cryptography and SSL/TLS Toolkit
PCRE Module - Perl Compatible Regular Expressions
SOAP Module - Creating and Calling Web Services
SOAP Module - Server Functions and Examples
►Zip Module - Managing ZIP Archive Files
References
Full Version in PDF/EPUB