Extract zip files in yii

Extract Zip Files Using Yii

I added the source code to extract the zip files using yii
SourceCode:

public function actionExtractfile($filename)
{
$filename='filename';     
$zipfile=DirDetails."/filename.zip";   
$zip = zip_open($zipfile);
$extract=DirDetails."/newfolder";        
if ($zip) 
{    
    if(!is_dir($extract))
         mkdir($extract);  
    while ($zip_entry = zip_read($zip)) {
 // if(zip_entry_name($zip_entry)==$filename)
 //if you need any specified file use this condition
    {                    
      $fp = fopen($extract."/".zip_entry_name($zip_entry), "w");                
      if (zip_entry_open($zip, $zip_entry, "r")) {
         $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
         fwrite($fp,"$buf");
         zip_entry_close($zip_entry);
         fclose($fp);
         break;
      }
     }
    }
   zip_close($zip);
  }
}