0

PHPを使用してrar/archiveファイルとフォルダーを抽出するのが好きです。しかし、私はこのスクリプトを使用してみました

<?php 
    $rar_file = rar_open('example.rar') or die("Can't open Rar archive");
    $entries = rar_list($rar_file); 
    foreach ($entries as $entry) { 
        echo 'Filename: ' . $entry->getName() . "\n"; 
        $entry->extract('/dir/extract/to/'); 
    } 
    rar_close($rar_file); 
?>
4

2 に答える 2

1

使用している機能は、最初にインストールする必要があります。

代わりに、 を使用してコマンドライン ツールを呼び出すこともできますがexec()、シェル インジェクションから身を守るようにしてください。

于 2013-01-28T05:07:06.480 に答える
0
$archive_name = '/full/path/to/file.rar'
$entry_name = 'path/to/archive/entry.txt'; //notice: no slash at the beginning
$dir_to_extract_to = '/path/to/extract/dir';
$new_entry_name = 'some.txt';


$rar = rar_open($archive_name) OR die('failed to open ' . $archive_name);
$entry = rar_entry_get($rar, $entry_name) OR die('failed to find ' . $entry_name . ' in ' . $archive_name);

// this will create all necessary subdirs under $dir_to_extract_to
$entry->extract($dir_to_extract_to); 
/* OR */

// this will create only one new file $new_entry_name in $dir_to_extract_to
$entry->extract('', $dir_to_extract_to.'/'.$new_entry_name); 

// this line is really not necessary
rar_close($rar);
于 2016-05-05T14:55:36.143 に答える