Jump to content

Archived

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

Demonic

Rar::extract

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?

Share this post


Link to post
Share on other sites
The example looks like it is doing that.  The argument to extract() is telling it which directory to put the files in.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.