How to Extract zip file on server

Mostly when you are transferring site from local server to the live server. You will upload the zip file of your project and then you will extract it on server.  But what if the hosting provider does not provide the zip extract functionality?

Recently while moving a site to one.com , i faced same problem. I uploaded the zip file to server then tried to extract it , but wait, there was no option to extract the zip file. So finally i had to look for a script which extracts the zip file on server.

So here is the code snippet which lets you extract the zip file on your server. Following these steps in order to extract the zip.

1) Create a php file (unzip.php) and add following code  snippet in your file.

2) Specify the name of the zip file you want to extract in following line.

$out = $unzip->open('file-name.zip');
3) That’s it. Run the unzip.php file in your browser.
<?php
$unzip = new ZipArchive;
$out = $unzip->open('file-name.zip');
if ($out === TRUE) {
 $unzip->extractTo(getcwd());
 $unzip->close();
 echo 'File unzipped';
} else {
 echo 'Something went wrong?';
}
?>
That’s it if “File unzipped” message is printed then this code worked perfectly for you.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s