Php method for extracting tar.gz files _ php skills

Source: Internet
Author: User
This article mainly introduces the phpdecompressed tar.gzformat file, and introduces the specific implementation skills of PHP installation pearextended and decompressed tar.gz format files. For more information, refer to the following article to describe phpdecompressed tar.gz format files. We will share this with you for your reference. The details are as follows:

1. php built-in compression and archive extension (phar)

$ Phar = new PharData('song.tar.gz '); // specifies whether the file to be decompressed in the path overwrites $ phar-> extraceid ('C:/tmp', null, true );

2. install the pear management tool first.

Linux

/Usr/local/php/bin/pear install Archive_Tar

Wamp by default, pear is not installed, go-pear.php for the old version, php5.3 need to download go-pear.phar

Put the downloaded file under the php Directory (any directory can be) execute the php go-pear.phar command, according to the prompt press enter

① Installation

# Pear install archive_tar will be installed by default when this class is actually installed

②,

/** Principle: the first 512 bytes of the tar package have their own fixed format. Based on these 512 bytes, you can obtain the file name and size of the package in combination with gzopen, gzread can decompress the gz format */$ tar_object = new Archive_Tar ("song.tar.gz"); $ tar_object-> extract ('C:/tmp ', true );

3. php calls external commands for decompression

// The script will be launched only after the command execution is complete. the popen command does not asynchronously execute error_reporting (E_ALL); ini_set ("display_errors", 1 ); $ handle = popen ("tar-xzvf song.tar.gz 2> & 1", 'r');/* while (! Feof ($ handle) {set_time_limit (3); $ buffer = fgets ($ handle); echo "$ buffer \ n"; ob_flush (); flush ();} */echo "start \ n"; pclose ($ handle); echo "end \ n ";

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.