php - How to check if a folder of specific name exists in zip file or not? -


i have zip file open using php ziparchive function , later need check if folder exists inside zip?

for example

i have abc.zip file. check if there sub-folder "xyz" in folder "pqr" inside zip file, if extracted abc / pqr / xyz sorry if not explained properly..  

i did researching , that's came it's working , added comments make easy understand

<?php $zip = new ziparchive; $dir = __dir__ . '/test'; // directory name $zipfilename = __dir__ . '/ahmad.zip'; // zip name $filename ='ahmad.php'; //file name  // unzip archive directory $res = $zip->open($zipfilename); if ($res === true) {     $zip->extractto($dir);     $zip->close(); } else {     echo 'failed, code:' . $res; }  // search file in directory $array = (scandir($dir)); if (in_array($filename, $array)) {     echo "file exists"; } else {     echo "file doesn't exist"; }  // delete directory after search done $it = new recursivedirectoryiterator($dir, recursivedirectoryiterator::skip_dots); $files = new recursiveiteratoriterator($it,              recursiveiteratoriterator::child_first); foreach($files $file) {     if ($file->isdir()){         rmdir($file->getrealpath());     } else {         unlink($file->getrealpath());     } } rmdir($dir);  ?> 

or can go

<?php $z = new ziparchive(); if($z->open('test.zip') === true ) {     if ($z->locatename('test.php') !== false)     {     echo "file exists";     }else {         echo "file doesn't exist";     } } else {     echo 'failed open zip archive'; }  ?> 

which lot easier user posted answer deleted added too


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -