Moauya Meghari
Moauya Meghari

Reputation: 501

extract .rar files to a specific directory in php

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.

Upvotes: 3

Views: 14355

Answers (3)

Waad Mawlood
Waad Mawlood

Reputation: 888

in Laravel to Extract rar file

first:
add this library to composer.json file

enter image description here



Second:
in controller to use it

use RarArchive;

**Last:**
$archive = RarArchive::open(public_path('storage/') . $pathFile);
$entries = $archive->getEntries();
foreach ($entries as $entry) {
  $entry->extract(public_path('storage/project/newfolder1'));
}
$archive->close();

Upvotes: 0

Max
Max

Reputation: 1

btw: extract offers overwrite as third parameter (second being an array of paths to extract)

Upvotes: 0

Oldskool
Oldskool

Reputation: 34837

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();

Upvotes: 7

Related Questions