How to unzip on server using ftp and php

Well, some times you just have the ftp information to upload the code and you decide to upload a zip file to upload whole code in a bunch quickly, that’s nice but what happens when you see your ftp doesn’t allow you to unzip the file?

That’s scary isn’t it?

Fortunately we still have a way to unzip a file by doing some php 🙂

Lets create an unzip file and upload it to server and run that file in browser it will unzip your zip file straight away.
Follow these steps.

1. create unzip.php by adding following php code


//mention your zip file
$file = '';

// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);

//create new zip class which is available in PHP core.
$zip = new ZipArchive();

//open your zip file using zip object
$res = $zip->open($file);

if ($res === TRUE) {
  // extract it to the desired path
  echo "Hurray... we got it unziped";
} else {
  echo "Please check permissions, I have no permission to unzip your file :(";

2. upload unzip.php to your server using ftp
3. run unzip.php in browser i.e

Note: if you are unable to run the unzip.php in browser check file permission in ftp normally these are 0755

That’s all, enjoy folks 🙂

One thought on “How to unzip on server using ftp and php

Leave a Reply

Your email address will not be published. Required fields are marked *