How to extract Zip Files with PHP?

In the previous post, we have created a random alphanumeric password generator script. In this post, I will show you, how to extract zip/compressed files using PHP. PHP has built-in extensions for dealing with compressed files.

Quick Tip : Simple PHP Password Generator

Following PHP function can be used to unzip the compressed files. It accepts two parameters, source i.e full path to zip file and destination i.e path to which files will be extracted.

//extract a file with php
function extractZip($src,$dest){
	$zip = new ZipArchive;
	$res = $zip->open($src);
	if ($res === TRUE) {
		echo 'Files Extracted Successfully!';
	} else {
		echo 'Extraction Failed!';

$src = "zip/";
$dest = "extractedfile/1/";
echo extractZip($src,$dest);

Author: rdlowrey

Source: Stack Overflow


Leave a Comment.