Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if file exist in zip archive

Tags:

php

zip

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;
}
like image 296
Ivan Avatar asked Apr 17 '13 22:04

Ivan


1 Answers

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;
}
like image 121
user2279205 Avatar answered Sep 16 '22 19:09

user2279205