Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Rar Functions : Rar::extract

Rar::extract

Extract entry from the archive ()

Example 2056. 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 2057. 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);

?>

Related Examples ( Source code ) » rar_extract











Code Examples / Notes » rar_extract

lubomir stefanov

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


christian boisjoli

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
}
?>


Change Language


Follow Navioo On Twitter
rar_close
rar_entry_get
Rar::extract
Rar::getAttr
Rar::getCrc
Rar::getFileTime
Rar::getHostOs
Rar::getMethod
Rar::getName
Rar::getPackedSize
Rar::getUnpackedSize
Rar::getVersion
rar_list
rar_open
eXTReMe Tracker