Unzip file in server using PHP ZipArchive

Once i wanted to upload WordPress folder which contains 1000's of files, if i choose to upload those files using FTP it will take much time.So i decided to upload it as zip file and extract it using php code. After googling i got a good source, how to extract / unzip file in server.

Follow the steps to unzip file in server:

  1. Create a file [root-dir(or)your-preferred-dir]/unzip-file.php in your server.
  2. Copy/paste below code in unzip-file.php and save it.
     $zip = new ZipArchive;
    $res = $zip->open('wordpress.zip');//File name in server.
    if ($res === TRUE) {
    $zip->extractTo('blog/');//Destination directory
    $zip->close();
    echo 'successfully extracted';
    } else {
    echo 'failed';
    }
  3. Upload your zip file in the same folder http://www.example.com/file.zip or your prefered folder as mentioned in above code.
Now run http://www.example.com/unzip-file.php file, your zip file will be extracted to the destination folder.
Is this post useful? Please comment below :-)

Comments

Popular posts from this blog

Send email from xampp localhost

Modify item price in cart after placing order using sales_quote_add_item

Convert long url to short url using tinyurl api