This article illustrates the method of Php_rar extension of PHP installation to realize RAR file reading and decompression. Share to everyone for your reference, specific as follows:
The PHP RAR archiving Module (PHP_RAR) is a module that reads and compresses RAR files, but does not provide a RAR compression (packaging) function.
1. First to download the DLL to PECL's RAR page. Choose to download the corresponding version of the DLL, depending on your situation.
PHP Version requirements: Php_rar module for PHP 5.2 and above, but for the Windows system, it seems only php5.3/5.4 corresponding DLL download.
2. The download is a ZIP package, which extracts the php_rar.pdb and php_rar.dll two files to the EXT subdirectory under the PHP installation directory.
3. Add a line to the php.ini Php_rar Extension Reference declaration Extension=php_rar.dll
4. If you use the Apache server, you need to restart Apache. PHP, which is loaded in fastcgi mode under IIS, does not require further action.
5. Write a test file to see if there are any problems.
6. If there is a problem, view the log file for the server.
Attached to the official test code test-rar.php:
<?php
$archive _name = '/full/path/to/file.rar '
$entry _name = ' path/to/archive/entry.txt ';//notice:no Slash at the beginning
$dir _to_extract_to = '/path/to/extract/dir ';
$new _entry_name = ' some.txt ';
$rar = Rar_open ($archive _name) or Die (' failed to open '. $archive _name);
$entry = Rar_entry_get ($rar, $entry _name) OR die (' failed to find '. $entry _name. ' In '. $archive _name);
This'll create all necessary subdirs under $dir _to_extract_to
$entry->extract ($dir _to_extract_to);
/* or//This'll create only one one
new file $new _entry_name in $dir _to_extract_to
$entry->extract ("", $dir _to_extract_to. ' /'. $new _entry_name);
This are really not necessary
rar_close ($rar);
? >
More about PHP Interested readers can view the site topics: "PHP Expanded Development course", "PHP file Operation Summary", "PHP Directory Operation skills Summary", "PHP common traversal algorithm and skills summary", "PHP Array" operation Skills Encyclopedia, " Introductory tutorials for PHP basic syntax, summary of PHP operations and operator usage, summary of PHP string usage, and a summary of PHP common database operations Tips
I hope this article will help you with the PHP program design.