PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Rar::getAttr> <rar_entry_get
Last updated: Fri, 10 Oct 2008

view this page in

Rar::extract

(No version information available, might be only in CVS)

Rar::extractアーカイブのエントリを展開する

説明

Rar
bool extract ( string $dir [, string $filepath ] )

Rar::extract() は、エントリのデータを dir に展開します。指定した dir に、エントリの名前と同名の新しいファイルを作成します。

パラメータ

dir

ファイルを展開するディレクトリへのパス。

filepath

dir の代わりに filepath が指定されている場合は、 Rar::extract() は指定したファイルに エントリのデータを展開します。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例1 Rar::extract() の例

<?php

$rar_file 
rar_open('example.rar') or die("Rar アーカイブのオープンに失敗しました");

$entry rar_entry_get($rar_file'Dir/file.txt') or die("そのようなエントリは見つかりません");

$entry->extract('/dir/to'); // /dir/to/Dir/file.txt を作成します
$entry->extract(false'/dir/to/new_name.txt'); // /dir/to/new_name.txt を作成します

?>

例2 アーカイブ内のすべてのファイルを展開する方法

<?php

/* erix こと Erik Jenssen によるサンプルです */

$filename "foobar.rar";
$filepath "/home/foo/bar/";

$rar_file rar_open($filepath.$filename);
$list rar_list($rar_file);
foreach(
$list as $file) {
    
$entry rar_entry_get($rar_file$file);
    
$entry->extract("."); // カレントディレクトリに展開します
}
rar_close($rar_file);

?>



add a note add a note User Contributed Notes
Rar::extract
chris at chrisphillips dot co dot uk
16-Jun-2008 05:05
There's a small problem in Example #2 by Erik Jenssen listed above.

This line:
$entry = rar_entry_get($rar_file, $file);

Should actually read:
$entry = rar_entry_get($rar_file, $file->name);

As it's an object, and the second parameter of rar_entry_get needs to be a string (of the file path).

Rar::getAttr> <rar_entry_get
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites