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...............?

Member Avatar for diafol

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

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

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
  }

Show the rest of your code. Are you sure you put the foreach in?

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);     

?>
commented: Thanks for sharing. +13
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.