To rename a folder, you must replace the folder name in the path of every file that it contains.(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL zip >= 1.5.0)
ZipArchive::renameIndex β ΠΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΠΎΠ²ΡΠ²Π°Π΅Ρ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΏΠΎ Π΅Π³ΠΎ ΠΈΠ½Π΄Π΅ΠΊΡΡ
ΠΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΠΎΠ²ΡΠ²Π°Π΅Ρ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΏΠΎ Π΅Π³ΠΎ ΠΈΠ½Π΄Π΅ΠΊΡΡ.
indexnew_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;
}
?>To rename a folder, you must replace the folder name in the path of every file that it contains.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.