Unzip Zip file with PHP

Posted by Unknown On Sunday 13 January 2013 0 comments

Unzip Zip file with PHP

       Yesterday I got a question from my friend, how unzip a word file that zipped using PHP. He wants extracting that file on server.Here using php default ZipArchive class.


To start with we should have the following minimum requirements
  • PHP with ziparchive class 

working

  1.     Install this code and edit zipfile name with your file name, and place file with same folder.
  2.     After execution there created a directory extracted and out put file will be there


Source code
01<?php
02$zip new ZipArchive;    
03    $res $zip->open('YourZipFile.zip');
04    if ($res === TRUE) {
05     $zip->extractTo('extracted/');
06     $zip->close();
07     echo 'Unzip was successful';
08     else {
09     echo 'Unzip was not successful';
10}
11?>

0 comments:

Post a Comment

Fashion