Jump to content


Photo

Rar::extract


  • Please log in to reply
3 replies to this topic

#1 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 18 September 2006 - 08:52 PM

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

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

?>

I was wondering is it possible to extract a the .rar files to a directory instead of a file?

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 19 September 2006 - 01:02 AM

The example looks like it is doing that.  The argument to extract() is telling it which directory to put the files in.

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 September 2006 - 04:46 AM

use copy

good luck
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 September 2006 - 11:45 AM

You can extract the contents of a rar file like so:
<?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);
?>

The following two lines from your 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
?>
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. Look here for more information on the extract function.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users