extract .rar files to a specific directory in php

Moauya Meghari picture Moauya Meghari · Apr 28, 2016 · Viewed 9.2k times · Source

I want to extract .rar file not .zip file using php I followed this example in php manual

php manual

the problem in this tutorial is not extract the files to directory, it prints the content of the file to browser.

Answer

Oldskool picture Oldskool · Apr 28, 2016

You should be able to extract the files from the archive with the RarEntry::extract method.

So something like:

$archive = RarArchive::open('archive.rar');
$entries = $archive->getEntries();
foreach ($entries as $entry) {
    $entry->extract('/extract/to/this/path');
}
$archive->close();