CakeFest 2024: The Official CakePHP Conference

ZipArchive::renameIndex

(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL zip >= 1.5.0)

ZipArchive::renameIndexインデックスを使用してエントリ名を変更する

説明

public ZipArchive::renameIndex(int $index, string $new_name): bool

インデックスを使用して、エントリ名を変更します。

パラメータ

index

名前を変更するエントリのインデックス。

new_name

新しい名前。

戻り値

成功した場合に true を、失敗した場合に false を返します。

例1 エントリ名の変更

<?php
$zip
= new ZipArchive;
$res = $zip->open('test.zip');
if (
$res === TRUE) {
$zip->renameIndex(2,'newname.txt');
$zip->close();
} else {
echo
'失敗、コード:' . $res;
}
?>
add a note

User Contributed Notes 2 notes

up
1
Jonathan Holvey
7 years ago
To rename a folder, you must replace the folder name in the path of every file that it contains.
up
0
troy_rudolph at bridge360 dot com
7 years ago
I have tried to rename folders inside the zip file using ZipArchive::renameIndex() and ZipArchive::renameName(). Neither was successful. I believe that this is not a bug and wanted to document it.
To Top