Hướng dẫn extract rar file using php script - giải nén tệp rar bằng tập lệnh php

Tôi muốn trích xuất tệp .zip không sử dụng tệp PHP, tôi đã theo ví dụ này trong hướng dẫn sử dụng PHP.rar file not .zip file using php I followed this example in php manual

Hướng dẫn sử dụng PHP

Vấn đề trong hướng dẫn này không phải là trích xuất các tệp vào thư mục, nó in nội dung của tệp vào trình duyệt.

Hỏi ngày 28 tháng 4 năm 2016 lúc 12:09Apr 28, 2016 at 12:09

Hướng dẫn extract rar file using php script - giải nén tệp rar bằng tập lệnh php

Moauya Megharimoauya MeghariMoauya Meghari

4512 Huy hiệu vàng5 Huy hiệu bạc20 Huy hiệu đồng2 gold badges5 silver badges20 bronze badges

2

Bạn sẽ có thể trích xuất các tệp từ kho lưu trữ với phương thức Rarentry :: Trích xuất.

Vì vậy, một cái gì đó như:

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

Đã trả lời ngày 28 tháng 4 năm 2016 lúc 12:23Apr 28, 2016 at 12:23

Hướng dẫn extract rar file using php script - giải nén tệp rar bằng tập lệnh php

2

BTW: extract cung cấp ghi đè dưới dạng tham số thứ ba (thứ hai là một mảng đường dẫn để trích xuất)

Đã trả lời ngày 2 tháng 12 năm 2019 lúc 19:48Dec 2, 2019 at 19:48

trong Laravel để trích xuất tệp rar

Đầu tiên: Thêm thư viện này vào tệp Composer.json
add this library to composer.json file

Hướng dẫn extract rar file using php script - giải nén tệp rar bằng tập lệnh php

Thứ hai: Trong bộ điều khiển để sử dụng nó
in controller to use it

use RarArchive;

**Cuối:**

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

Đã trả lời ngày 11 tháng 2 năm 2021 lúc 17:23Feb 11, 2021 at 17:23

Hướng dẫn extract rar file using php script - giải nén tệp rar bằng tập lệnh php

1

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

(PECL RAR> = 0,1)Extract entry from the archive

Sự mô tả

PECL RAR 3.0.0 RarEntry::extract(
    string $dir,
    string $filepath = "",
    string $password = NULL,
    bool $extended_data = false
): bool

use RarArchive;
7 đã được thêm vào. extracts the entry's data. It will create new file in the specified dir with the name identical to the entry's name, unless the second argument is specified. See below for more information.

Hỗ trợ cho các tài liệu lưu trữ RAR với tên nhập lặp đi lặp lại không còn bị lỗi.

Ví dụ

Ví dụ #1 Rarentry :: Trích xuất () Ví dụ

Ví dụ #2 Cách trích xuất tất cả các tệp trong kho lưu trữ:

Xem thêm

RARENTRY :: getStream () - Nhận trình xử lý tệp để nhập

$archive = RarArchive::open(public_path('storage/') . $pathFile);
$entries = $archive->getEntries();
foreach ($entries as $entry) {
  $entry->extract(public_path('storage/project/newfolder1'));
}
$archive->close();
6 bao bọcrar_open(), if any, will be used. If a wrong password is given, either explicitly or implicitly via rar_open(), CRC checking will fail and this method will fail and return false. If no password is given and one is required, this method will fail and return false. You can check whether an entry is encrypted with RarEntry::isEncrypted().

(PECL RAR> = 0,1)

Rarentry :: Trích xuất - Trích xuất mục từ kho lưu trữ

use RarArchive;
8, extended information such as NTFS ACLs and Unix owner information will be set in the extract files, as long as it's present in the archive.

Cảnh báo

Trước phiên bản 2.0.0, chức năng này sẽ không xử lý chính xác các đường dẫn tương đối. Sử dụng realpath () như một cách giải quyết.realpath() as a workaround.

Trả về giá trị

Trả về

use RarArchive;
8 khi thành công hoặc false về thất bại.
use RarArchive;
8
on success or false on failure.

Thay đổi

Phiên bảnSự mô tả
PECL RAR 3.0.0
use RarArchive;
7 đã được thêm vào.
PECL RAR 3.0.0
use RarArchive;
7 đã được thêm vào.

Hỗ trợ cho các tài liệu lưu trữ RAR với tên nhập lặp đi lặp lại không còn bị lỗi.

Ví dụRarEntry::extract() example

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

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

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

Ví dụ #1 Rarentry :: Trích xuất () Ví dụ

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

Ví dụ #2 Cách trích xuất tất cả các tệp trong kho lưu trữ:

  • Xem thêm
  • RARENTRY :: getStream () - Nhận trình xử lý tệp để nhập