How to unzip the folders and files in PHP ?

Recently I wanted to move wordpress development thing to one customer website. I was always complete these kind of works with cpanel very easily.

Unexpectedly this client having some hosting account where the cpanel does not exist, so it was a kind of work for me to move each and every file separately as FTP was the one and only way to upload the files.

And it was keep on getting errored out between some files as I have to move totally 235MB of files. so I thought to make this as zip and extract using the exectuion from the website directly.

And this is the script which helped me to extract the zip file and also to complete my site migration job so easily.\

PHP Unzip Source Code:

Just modify the zip file name and the path (if required, by default in the same directory it extracts every files and folders).

// Get Project path
define('_PATH', dirname(__FILE__));

// Zip file name
$filename = '';
$zip = new ZipArchive;
$res = $zip->open($filename);
if ($res === TRUE) {

  // Unzip path
  $path = _PATH."/";

  // Extract file

  echo 'Unzip!';
} else {
  echo 'failed!';

Leave a Reply