downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Rar::getAttr> <rar_entry_get
Last updated: Fri, 20 Nov 2009

view this page in

Rar::extract

(PECL rar >= 0.1)

Rar::extractExtract entry from the archive

Description

Rar
bool extract ( string $dir [, string $filepath ] )

Rar::extract() extracts entry's data to the dir . It will create new file in the specified dir with the name identical to the entry's name.

Parameters

dir

Path to the directory where files should be extracted.

filepath

If parameter filepath is specified instead dir , Rar::extract() will extract entry's data to the specified file.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example #1 Rar::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::getAttr> <rar_entry_get
Last updated: Fri, 20 Nov 2009
 
add a note add a note User Contributed Notes
Rar::extract
chris at chrisphillips dot co dot uk
15-Jun-2008 08:05
There's a small problem in Example #2 by Erik Jenssen listed above.

This line:
$entry = rar_entry_get($rar_file, $file);

Should actually read:
$entry = rar_entry_get($rar_file, $file->name);

As it's an object, and the second parameter of rar_entry_get needs to be a string (of the file path).
Christian Boisjoli
27-Jul-2007 07:59
As remarked by Lubomir Stefanov, example 2026 has an error. Another way to correct this error would be to replace the foreach loop as follows:

<?php
foreach($list as $entry) {
   
$entry->extract("."); // extract to the current dir
}
?>
Lubomir Stefanov
26-Feb-2007 04:45
One edit for function by Erik Jenssen
Line $entry = rar_entry_get($rar_file, $file);
must be $entry = rar_entry_get($rar_file, $file->name);

because $file is a object

Rar::getAttr> <rar_entry_get
Last updated: Fri, 20 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites