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 ";