Unzip Uploaded Files On Server Using PHP
Web designers and developers know that compressing files into one single archive file such as a ZIP file is always a necessity when it comes to uploading huge amount of files onto a server, which means having to unzip the file once it has been uploaded.
People have tried to come up with ways to automatically do the latter using a variety of PHP codes. Below is probably the shortest code out there that you can use to unzip a file on your PHP server.
<?php
$zip = new ZipArchive;
$res = $zip->open('sc.zip');
if ($res === TRUE) {
$zip->extractTo('sc/');
$zip->close();
echo 'ok';
} else {
echo 'failed';
} ?>
This is very useful in cases where you don’t have access to the cpanel or shell. Just make sure that the directory where you want to extract the files to has ‘write’ permissions or else you’ll run into some issues.
(Code posted by zealmurapa via Snipplr).