Home > Backend Development > PHP Tutorial > How to install php_rar extension in php to read and decompress rar files

How to install php_rar extension in php to read and decompress rar files

高洛峰
Release: 2023-03-03 13:54:02
Original
2060 people have browsed it

The example in this article describes how to install the php_rar extension in php to read and decompress rar files. Share it with everyone for your reference, the details are as follows:

PHP Rar Archiving module (php_rar) is a module for reading and decompressing rar files, but it does not provide RAR compression (packaging) function.

1. First go to PECL's RAR page to download the DLL. Choose to download the corresponding version of the DLL according to your own situation.

PHP version requirements: The php_rar module is suitable for php 5.2 and above, but for Windows systems, it seems that only php5.3 / Download the DLL corresponding to 5.4.

2. Download a zip package, unzip the two files php_rar.pdb and php_rar.dll into the ext subdirectory under the PHP installation directory.

3. Add a line of php_rar extension reference statement extension=php_rar.dll to php.ini

4. If you use the Apache server, you need to restart Apache. PHP loaded in FastCGI mode under IIS does not require further operations.

5. Write a test file to see if there are any problems

6. If there are problems, check the server’s log file.

Attached is the official test code test-rar.php:

<?php
$archive_name = &#39;/full/path/to/file.rar&#39;
$entry_name = &#39;path/to/archive/entry.txt&#39;; //notice: no slash at the beginning
$dir_to_extract_to = &#39;/path/to/extract/dir&#39;;
$new_entry_name = &#39;some.txt&#39;;
$rar = rar_open($archive_name) OR die(&#39;failed to open &#39; . $archive_name);
$entry = rar_entry_get($rar, $entry_name) OR die(&#39;failed to find &#39; . $entry_name . &#39; in &#39; . $archive_name);
// this will create all necessary subdirs under $dir_to_extract_to
$entry->extract($dir_to_extract_to);
/* OR */
// this will create only one new file $new_entry_name in $dir_to_extract_to
$entry->extract(&#39;&#39;, $dir_to_extract_to.&#39;/&#39;.$new_entry_name);
// this line is really not necessary
rar_close($rar);
?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template