When you rename a file in an archive using the function above and the target file name already exists, the function will return FALSE as a result.(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL zip >= 1.5.0)
ZipArchive::renameName β ΠΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΠΎΠ²ΡΠ²Π°Π΅Ρ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΏΠΎ Π΅Π³ΠΎ ΠΈΠΌΠ΅Π½ΠΈ
ΠΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΠΎΠ²ΡΠ²Π°Π΅Ρ ΡΠ»Π΅ΠΌΠ΅Π½Ρ, Π·Π°Π΄Π°Π½Π½ΡΠΉ ΠΏΠΎ ΠΈΠΌΠ΅Π½ΠΈ.
namenew_name
Π€ΡΠ½ΠΊΡΠΈΡ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ true, Π΅ΡΠ»ΠΈ Π²ΡΠΏΠΎΠ»Π½ΠΈΠ»Π°ΡΡ ΡΡΠΏΠ΅ΡΠ½ΠΎ, ΠΈΠ»ΠΈ false, Π΅ΡΠ»ΠΈ Π²ΠΎΠ·Π½ΠΈΠΊΠ»Π° ΠΎΡΠΈΠ±ΠΊΠ°.
ΠΡΠΈΠΌΠ΅Ρ #1 ΠΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ°
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->renameName('currentname.txt','newname.txt');
$zip->close();
} else {
echo 'ΠΎΡΠΈΠ±ΠΊΠ° Ρ ΠΊΠΎΠ΄ΠΎΠΌ:' . $res;
}
?>When you rename a file in an archive using the function above and the target file name already exists, the function will return FALSE as a result.