A veeery simple function to RAR files, I'm not proud of it.
Since there's no way to create RAR files in PHP (due to licensing, patents or whatever), I'm taking some advantage from the command-line RARing tool that comes with WinRAR (in the WinRAR program files named "rar.exe").
<?php
function RARFiles($Output='output.rar',$Files=array()) {
$Data='';
for($i=0;$i<count($Files);$i++)
$Data.="\"{$Files[$i]}\" ";
exec("rar.exe a \"{$Output}\" {$Data}");
}
$Files=array('file1.ext','file2.ext','file3.ext');
RARFiles('asdf.rar',$Files);
// asdf.rar created.
?>
There's no error checking, so make sure you check that your expected RAR file exists before doing anything with it.
Hopefully one day, PHP will be able to be allowed to create RAR files.
Примери
Example #1 Rar extension overview example
<?php
$rar_file = rar_open('example.rar') or die("Can't open Rar archive");
$entries = rar_list($rar_file);
foreach ($entries as $entry) {
echo 'Filename: ' . $entry->getName() . "\n";
echo 'Packed size: ' . $entry->getPackedSize() . "\n";
echo 'Unpacked size: ' . $entry->getUnpackedSize() . "\n";
$entry->extract('/dir/extract/to/');
}
rar_close($rar_file);
?>
This example opens a Rar file archive and extracts each entry to the specified directory.
Nitrogen
17-Nov-2010 01:43
landavia81 at gmail dot com
21-Jan-2009 03:00
for unknown reason.. many programer has problem with php_rar (in windows).. i came up with this ... and it work.
basicly is same as above but only extract only. The problem will come up if the file rar corrupt, exist and soon
_______________________________
<?php
$appRar ="C:/Program Files/WinRAR/unrar.exe";
#this is false..
$appRar = '"C:\Program Files\WinRAR\unrar.exe"';
#change this
$opt="e";
$target="1.rar";
$do ="$appRar $opt $target";
exec($do,$aOut);
print_r($aOut);
?>
-------------------------------------------------
For windows user: try using bat file for test.
all user: please read man unrar, above using e because this only extract. But you should notice about other option like "y","x", etc
i type the option here if you too lazy
http://landavia.multiply.com/journal/item/284/option_for_unrar
$aOut are array for the output after you run the script $do
