将 .rar 文件解压缩到 php 中的特定目录

extract .rar files to a specific directory in php

我想使用 php 提取 .rar 文件 而不是 .zip 文件 我在 php 手册

中遵循了这个例子

php manual

本教程中的问题是没有将文件解压到目录, 它将文件的内容打印到浏览器。

您应该能够使用 RarEntry::extract 方法从存档中提取文件。

所以像这样:

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

顺便说一句:extract 提供覆盖作为第三个参数(第二个是要提取的路径数组)

在 Laravel 中提取 rar 文件

第一:
将此库添加到 composer.json 文件



第二个:
在控制器中使用它

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