When developing a Web application, it is very likely that you will encounter different formats of file--csv data, password files, XML encoded content, and different forms of binary data. Your PHP scripts will need to interact with these files frequently, reading data from them, and writing data to them. Since there are so many file formats to work with, you should not accidentally have several types of built-in functions and external libraries in PHP to connect and use almost any file format that you can name.
This PHP Create zip archive Guide is about such a file format, which may be encountered by application developers almost every day: Zip format. In general, this format is used to transfer files through e-mail and remote connections, to compress multiple files into an archive file, thus reducing the file's hard disk to occupy space and making it easier to move them. PHP can read and create these zip files through its zziplib plugin and pear's Archive_zip class.
I will assume that you already have a functioning Apache, that you have PHP installed, and that the Pear Archive_zip class is installed correctly.
Note: You can install the Pear Archive_zip package directly from the Web, or you can download it and take advantage of the instructions provided.
PHP Create zip archive file
Let's start with a simple example: dynamically create a ZIP file that includes several other files. Start with the script in List A.
List A
- < ? PHP
- Include (' archive/zip.php ');
- Imports
- $ obj = New archive_zip (' Test.zip ');
- Name of the zip file
- $ Files = Array (' Mystuff/ad.gif ',
- ' Mystuff/alcon.doc ',
- ' Mystuff/alcon.xls ');
- Files to store
- if ($obj->Create ($files)) {
- Echo ' Created successfully! ';
- } else {
- Echo ' Error in file Creation ';
- }
- ?>
These are the tips for PHP to create a zip archive file.
http://www.bkjia.com/PHPjc/445910.html www.bkjia.com true http://www.bkjia.com/PHPjc/445910.html techarticle when developing a Web application, it is very likely that you will encounter different formats of file CSV data, password files, XML encoded content, and different forms of binary data. Your PHP script will need ...