Jump to content

Rar::extract


Demonic

Recommended Posts

Was reading up on the PHP offline manual and i came across this:

[code]
<?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

?>
[/code]

I was wondering is it possible to extract a the .rar files to a directory instead of a file?
Link to comment
https://forums.phpfreaks.com/topic/21194-rarextract/
Share on other sites

You can extract the contents of a rar file like so:
[code]<?php
$rar_file = rar_open("example.rar") or die("Can't open Rar archive");
$entries = rar_list($rar_file);
foreach($entries as $entry) {
    echo "Extracting: ".$entry->getName()."<br/>";
    $entry->extract("/dir/extract/to/");
}
rar_close($rar_file);
?> [/code]

The following two lines from your code:
[code]<?php
$entry->extract('/dir/to'); // create /dir/to/Dir/file.txt
$entry->extract(false, '/dir/to/new_name.txt'); // create /dir/to/new_name.txt
?>[/code]
The first extract is extracting the file to the selected directory, where the second extract is dumping the file contents into a text file, for some reason. [url=http://uk.php.net/manual/en/function.rar-extract.php]Look here[/url] for more information on the extract function.
Link to comment
https://forums.phpfreaks.com/topic/21194-rarextract/#findComment-94560
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.