简体   繁体   中英

How to check if file exist in zip archive

i have zip archive and after extract him i need to check if moduleConfig.xml exist inside zip archive. How i can do that.

I try this

$zip = new ZipArchive();
if($zip->open('test.zip') === TRUE )
{
    if(file_exists($zip->getFromName('moduleConfig.xml')))
    {
        echo "Config exists";
        // Do somthing
    }
}
else {
    echo 'Failed code:'. $res;
}

It should be like this:

$zip = new ZipArchive();
if($zip->open('test.zip') === TRUE )
{
    if ($zip->locateName('moduleConfig.xml') !== false)
    {
    echo "Config exists";
    }
}
else {
    echo 'Failed code:'. $res;
}

try:

if ($zip->locateName('moduleConfig.xml') !== false)
{
    echo "Config exists";
}

You can do this by using getFromName

        $zip = new ZipArchive();

        if($zip->open('test.zip') === TRUE )
        {
            if($zip->getFromName('moduleConfig.xml') != false)
            {
                echo "Config exists";
                // Do somthing
            }
        }
        else {
            echo 'Failed code:'. $res;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM