How to check if file exist in zip archive
11,778
Solution 1
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;
}
Solution 2
try:
if ($zip->locateName('moduleConfig.xml') !== false)
{
echo "Config exists";
}
Comments
-
Ivan almost 2 years
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; }
-
dbf about 11 yearsyou tried this, but it did what instead?
-
Ivan about 11 yearsI try this and this dont work. I dont understand ur question.
-
-
Hector over 7 yearsNote: You should check it using
!== false
because it can return0
when file exists. soif ( $zip->locateName('file.xml') ) {...}
doesn't works correctly. more info