(PECL rar >= 0.1)
RarEntry::extract — Extract entry from the archive
$dir,$filepath = "",$password = NULL,$extended_data = false
RarEntry::extract() extracts the entry's data.
It will create new file in the specified
dir with the name identical to the entry's name,
unless the second argument is specified. See below for more information.
dirfilepath is not. If both
parameters are empty an extraction to the current directory will be
attempted.
filepathdir and the original file name.
passwordfalse.
If no password is given and one is required, this method will fail and return false.
You can check whether an entry is encrypted with RarEntry::isEncrypted().
extended_datatrue, extended information such as NTFS ACLs and Unix owner information will be set in the extract
files, as long as it's present in the archive.
Prior to version 2.0.0, this function would not handle relative paths correctly. Use realpath() as a workaround.
| Version | Description |
|---|---|
| PECL rar 3.0.0 |
extended_data was added.
|
| PECL rar 3.0.0 | Support for RAR archives with repeated entry names is no longer defective. |
Example #1 RarEntry::extract() example
<?php
$rar_file = rar_open('example.rar') or die("Failed to open Rar archive");
$entry = rar_entry_get($rar_file, 'Dir/file.txt') or die("Failed to find such entry");
$entry->extract('/dir/to'); // create /dir/to/Dir/file.txt
$entry->extract(false, '/dir/to/new_name.txt'); // create /dir/to/new_name.txt
?>Example #2 How to extract all files in archive:
<?php
/* example by Erik Jenssen aka erix */
$filename = "foobar.rar";
$filepath = "/home/foo/bar/";
$rar_file = rar_open($filepath.$filename);
$list = rar_list($rar_file);
foreach($list as $file) {
$entry = rar_entry_get($rar_file, $file);
$entry->extract("."); // extract to the current dir
}
rar_close($rar_file);
?>rar:// wrapper