How to Extract or Unzip files from a .zip file using PHP

Here is the simple code which will extract a zip file. Here we are using pclzip.lib file to extract files. You no need to install any other library to your server.

First download pclzip.lib file.

Now use the below code to extract your zip file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html>
<head><title>unzip | electrofriends.com</title>
</head>
<body>
<?php	
require_once('pclzip.lib.php'); 
$zipfile = new PclZip('filename.zip');
if ($zipfile -> extract() == 0) {
	echo 'Error : ' . $zipfile -> errorInfo(true);
}else{
	echo 'File Extracted!';
} 
?>
</body>
</html>

One Response to “How to Extract or Unzip files from a .zip file using PHP”

Leave a Reply