Reputation: 501
I want to extract .rar file not .zip file using php I followed this example in 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
Reputation: 888
in Laravel to Extract rar file
first:
add this library to composer.json file
Second:
in controller to use it
use RarArchive;
$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
Reputation: 1
btw: extract
offers overwrite as third parameter (second being an array of paths to extract)
Upvotes: 0
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