Friday, 23 January 2015

unzip a zip file using php

<?php

function unZip($urllocation,$newurlLocation){
if(exec("unzip $urllocation",$arr)){
mkdir($newurlLocation);
for($i = 1;$i< count($arr);$i ){
$file = trim(preg_replace("~inflating: ~","",$arr[$i]));
copy($urllocation.'/'.$file,$newurlLocation.'/'.$file);
unlink($urllocation.'/'.$file);
}
return TRUE;
}else{
return FALSE;
}
}

if(unzip('zipfile/test.zip','unziped/myNewZip'))
echo 'Unzipped!';
else
echo 'Failed';
?>

0 comments:

Post a Comment