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? Link to comment https://forums.phpfreaks.com/topic/21194-rarextract/ 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. Link to comment https://forums.phpfreaks.com/topic/21194-rarextract/#findComment-94347 Share on other sites More sharing options...
redarrow Posted September 19, 2006 Share Posted September 19, 2006 use copygood luck Link to comment https://forums.phpfreaks.com/topic/21194-rarextract/#findComment-94439 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. Link to comment https://forums.phpfreaks.com/topic/21194-rarextract/#findComment-94560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.