PHP Development notes series (7)-compression and decompression

Source: Internet
Author: User
PHP Development notes series (7)-compression and decompression ???? Compression and decompression may not be used much in general web applications, but are commonly used in the following application scenarios, such as compressing database backup files, package multiple files in one file for download, compress the files that the customer packs and uploads, and explain them. it is necessary to familiarize yourself with common functions and classes for compression and decompression .??? PHP Development notes series (7)-compression and decompression PHP Development notes series (7)-compression and decompression

?

??? Compression and decompression may not be used much in general web applications, but are commonly used in the following application scenarios, such as compressing database backup files, package multiple files in one file for download, compress and interpret the files that the customer packs and uploads, and familiarize yourself with common functions and classes for compression and decompression.


??? This article "PHP Development notes series (7)-compression and decompression" will be the seventh article in "PHP development Notes Series (XAMPP + PhpEclipse + XDebug, describes how to use the Pear plug-in Archive Tar to perform regular file compression and decompression operations.


???1. use the Archive_Tar class for file compression

???? The Archive_Tar class is located in the Archive/Tar. php file in the Pear folder, and requires a small amount of code to compress files using this class. Step: 1) instantiate this class. The first construction parameter is the compressed target file name, and the second construction parameter is the compression type (gz: gzip compression, bz2 use bzip2 compression ), if the second parameter is omitted, only the Archive_Tar object is packaged and not compressed. 2) after the Archive_Tar object is created, input the file name data to the create method of the object. The code is as follows:

???

file:tar.phpurl:http://localhost:88/archive/tar.php
 create($files);        echo 'xdebug.tar.gz exist:'.file_exists($tarFile).'
'; echo 'xdebug.tar.gz mtime:'.date('Y-m-d h-i:s', filemtime($tarFile)).'
'; echo 'xdebug.tar.gz :atime:'.date('Y-m-d h-i:s', fileatime($tarFile)).'
'; echo 'xdebug.tar.gz size:'.filesize($tarFile).'
';?>

?

???2.Use Archi Ve_Tar class for file compression

? ? The decompression process is similar to the compression process. The steps are as follows: 1) instantiate the Archive_Tar object and upload it to the source compressed file name; 2) after the object is instantiated, input a target folder name to the decompressed method extract, the files in the compressed package will be released to the target folder. The code is as follows:

?

file:extract.phpurl:http://localhost:88/archive/extract.php
 extract($targetDir);        $dp = opendir($targetDir);    while ($entry = readdir($dp)){        if(is_dir($entry))        {            echo '[DIR] '.$entry. '
'; }elseif (is_file($entry)) { echo '[FILE] '.$entry. '
'; } } closedir($dp);?>

?

?

?

??? Address: http://ryan-d.iteye.com/blog/1543417

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.