1

i wanna extract many ziped folders, but i am not successfull. i have find out problem but not the solution of that.
whenever i pass an array or associative array in a for loop to code given below to extract all ziped folders to unzip it stop working.

     $zip = new ZipArchive;
     if ($zip->open($arrayName) === true){
         //not work
     }

but i pass only one file name it accept but in case of array i dont work.

     $zip = new ZipArchive;
     if ($zip->open('abc.zip') === true){
         //it will work
     }

so now i wanna know that how i can extract many ziped folders...............?

Edited by shujat132

3
Contributors
4
Replies
8
Views
5 Years
Discussion Span
Last Post by shujat132
1

I'm not familiar with this one, but how about?

$zip = new ZipArchive;
foreach($arrayName as $name){
    if ($zip->open($name) === true){
         //hopefully!
     }
}

Edited by diafol

0

hi
thanks dear diafol for your reply
but again same results, thats not working and if open function in if statement is not accepting any array

 if ($zip->open($name) === true){
      //not work
  }

Edited by shujat132

1

hi daers
how are you...?
Well, diafol, pritaeas thanks for your guide line, bcoz i have done it now,
first i was implementing your suggestion in a wrong maner. but now i have done it with this piece of code.

<?php

//this function will open folder and read all content and put them on array
function foldersContent($path){
    if ($handle = opendir($path)) {     
        $i = 0;
        $content = array();
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {              
                $i++;
                $content[] = $entry;
            }           
        }

        print 'Total number of files are: '.$i.'<br>';
        closedir($handle);  
    }
    return $content;
}

function unzip($fileName, $location){   
    $zip = new ZipArchive;
    foreach($fileName as $name1){
        $add = $location.$name1;

        if ($zip->open($add) === true) { 

            for($i = 0; $i < $zip->numFiles; $i++) {                         
                $zip->extractTo($location, array($zip->getNameIndex($i)));
                echo '<br/>Extracting '.$name1.'<br/>';               
            }                    
            $zip->close();                    
        }else{
            echo '<br/>in else part.<br/>';
        }       
    }
}


$dir = 'd:/extract/';   //from where content of directory will be readed
$content =foldersContent($dir);


$location = "D:/extract/";  //where files will be extracted         
unzip($content, $location);     

?>

Edited by shujat132

Votes + Comments
Thanks for sharing.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.