Demonic Posted September 18, 2006 Share Posted September 18, 2006 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? Quote Link to comment Share on other sites More sharing options...
btherl Posted September 19, 2006 Share Posted September 19, 2006 The example looks like it is doing that. The argument to extract() is telling it which directory to put the files in. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 19, 2006 Share Posted September 19, 2006 use copygood luck Quote Link to comment Share on other sites More sharing options...
zq29 Posted September 19, 2006 Share Posted September 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.