PHP UnRar.exe into a specific directory

1.5k views Asked by At

Ive just found this script and it is exactly what im looking for, However how can i tell it to extract the files into a specific folder?

Here is the script

<?php
$winRAR = '"C:\Program Files\WinRAR\UnRAR.exe"';
$file="test.rar";
$do ="$winRAR e $file";
exec("$winRAR /?");
print_r($aOut);
exec($do,$aOut); 
print_r($aOut);
?>

Im going to be extracting multiple files so i would like it to extract each archive into a a folder with the same name as the archive. So if the rar was called "Test" i want it to extract to a folder called /test/ and extract the files there?

Many Thanks in advance!

2

There are 2 answers

1
Burpy Burp On

I think what you are trying to do may be easier using PHP's RAR extension. http://www.php.net/manual/en/book.rar.php

0
zjoe On

I suggest you to use the following command:

$do ="$winRAR x -ad $file $destinationPath";

Where $destinationPath is a destination path.

The "x" command will keep directory structure stored in archive in contrast with "e" command, which extracts files without subdirectories.

The "-ad" command line switch tells unrar to extract archive foo.rar to the $destinationPath/foo directory.

Command line commands and switches are listed in WinRAR help file, in section "Command line mode".