Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- ziparchive::addEmptyDir --EXTENSIONS-- zip --FILE-- <?php $dirname = __DIR__ . '..

Decoded Output download

--TEST--
ziparchive::addEmptyDir
--EXTENSIONS--
zip
--FILE--
<?php

$dirname = __DIR__ . '/';
include $dirname . 'utils.inc';
$file = $dirname . 'oo_addemptydir.zip';

copy($dirname . 'test.zip', $file);

$zip = new ZipArchive;
if (!$zip->open($file)) {
    exit('failed');
}

var_dump($zip->lastId); // -1 (nothing added)
$zip->addEmptyDir('emptydir');
var_dump($zip->lastId); // 4
$zip->addEmptyDir('emptydir');
var_dump($zip->lastId); // -1 (already exists)
$zip->addEmptyDir('emptydir', ZipArchive::FL_OVERWRITE);
var_dump($zip->lastId); // 4
if ($zip->status == ZIPARCHIVE::ER_OK) {
    if (!verify_entries($zip, [
        "bar",
        "foobar/",
        "foobar/baz",
        "entry1.txt",
        "emptydir/"
    ])) {
        echo "failed
";
    } else {
        echo "OK";
    }
    $zip->close();
} else {
    echo "failed3
";
}
@unlink($file);
?>
--EXPECT--
int(-1)
int(4)
int(-1)
int(4)
OK

Did this file decode correctly?

Original Code

--TEST--
ziparchive::addEmptyDir
--EXTENSIONS--
zip
--FILE--
<?php

$dirname = __DIR__ . '/';
include $dirname . 'utils.inc';
$file = $dirname . 'oo_addemptydir.zip';

copy($dirname . 'test.zip', $file);

$zip = new ZipArchive;
if (!$zip->open($file)) {
    exit('failed');
}

var_dump($zip->lastId); // -1 (nothing added)
$zip->addEmptyDir('emptydir');
var_dump($zip->lastId); // 4
$zip->addEmptyDir('emptydir');
var_dump($zip->lastId); // -1 (already exists)
$zip->addEmptyDir('emptydir', ZipArchive::FL_OVERWRITE);
var_dump($zip->lastId); // 4
if ($zip->status == ZIPARCHIVE::ER_OK) {
    if (!verify_entries($zip, [
        "bar",
        "foobar/",
        "foobar/baz",
        "entry1.txt",
        "emptydir/"
    ])) {
        echo "failed\n";
    } else {
        echo "OK";
    }
    $zip->close();
} else {
    echo "failed3\n";
}
@unlink($file);
?>
--EXPECT--
int(-1)
int(4)
int(-1)
int(4)
OK

Function Calls

None

Variables

None

Stats

MD5 b2284fa9895e4a8a9a541c52cc51bf92
Eval Count 0
Decode Time 72 ms