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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.