PHP RAR
The Rar is a powerful and effective archiver created by Eugene Roshal.
This extension gives you the possibility to read Rar archives but doesn't support writing Rar archives, because this is not supported by the UnRar library and is directly prohibited by its license.
A simple example to extract a RAR extension filesystem
<?php
$rar_file = rar_open('example.rar') or die("Can't open Rar archive");
$entries = rar_list($rar_file);
foreach ($entries as $entry) {
echo 'Filename: ' . $entry->getName() . "\n";
echo 'Packed size: ' . $entry->getPackedSize() . "\n";
echo 'Unpacked size: ' . $entry->getUnpackedSize() . "\n";
$entry->extract('/dir/extract/to/');
}
rar_close($rar_file);
?>
Output
Requirements
No external libraries are needed to build this extension.
Installation
Rar is currently available through PECL » http://pecl.php.net/package/rar.
Also, you can use the PECL installer to install the Rar extension, using the following command: pecl -v install rar.
You can always download the tar.gz package and install Rar by hand
Rar installation
tar -xvf rar-xxx.tar
cd rar-xxx
phpize
./configure && make && make install
Windows users will enable php_rar.dll inside of php.ini in order to use these functions.
A DLL for this PECL extension is currently unavailable. See also the building on Windows section.
Run-time Configuration
This extension has no configuration directives defined in php.ini.
Resource Types
This extension registers three internal classes: The archive representations returned by rar_open() – RarArchive –, the entry representations returned by rar_list() and rar_entry_get() – RarEntry and the exception type RarException.
This extension also registers a stream resource, called "rar" and a URL wrapper called "rar wrapper" and registered under the prefix "rar".
Predefined Constants
PHP RAR extension also provided some predefined constants,
In order to use this extension has either been compiled into PHP or dynamically loaded at runtime.
- RAR_HOST_MSDOS (integer)
- Use RarEntry::HOST_MSDOS instead.
- RAR_HOST_OS2 (integer)
- Use RarEntry::HOST_OS2 instead.
- RAR_HOST_WIN32 (integer)
- Use RarEntry::HOST_WIN32 instead.
- RAR_HOST_UNIX (integer)
- Use RarEntry::HOST_UNIX instead.
- RAR_HOST_BEOS (integer)
- Use RarEntry::HOST_BEOS instead.
Rar Functions
- rar_wrapper_cache_stats — Cache hits and misses for the URL wrapper
Rar Predefined Classes
- RarArchive — The RarArchive class
- RarArchive::close — Close RAR archive and free all resources
- RarArchive::getComment — Get comment text from the RAR archive
- RarArchive::getEntries — Get the full list of entries from the RAR archive
- RarArchive::getEntry — Get entry object from the RAR archive
- RarArchive::isBroken — Test whether an archive is broken (incomplete)
- RarArchive::isSolid — Check whether the RAR archive is solid
- RarArchive::open — Open RAR archive
- RarArchive::setAllowBroken — Whether opening broken archives is allowed
- RarArchive::__toString — Get text representation
- RarEntry — The RarEntry class
- RarEntry::extract — Extract entry from the archive
- RarEntry::getAttr — Get attributes of the entry
- RarEntry::getCrc — Get CRC of the entry
- RarEntry::getFileTime — Get entry last modification time
- RarEntry::getHostOs — Get entry host OS
- RarEntry::getMethod — Get pack method of the entry
- RarEntry::getName — Get name of the entry
- RarEntry::getPackedSize — Get packed size of the entry
- RarEntry::getStream — Get file handler for entry
- RarEntry::getUnpackedSize — Get unpacked size of the entry
- RarEntry::getVersion — Get minimum version of RAR program required to unpack the entry
- RarEntry::isDirectory — Test whether an entry represents a directory
- RarEntry::isEncrypted — Test whether an entry is encrypted
- RarEntry::__toString — Get text representation of entry
- RarException — The RarException class
- RarException::isUsingExceptions — Check whether error handling with exceptions is in use
- RarException::setUsingExceptions — Activate and deactivate error handling with exceptions