Skip to main content

Posts

Showing posts from November, 2013

unzip file with php

This is a little php script to unzip file using php




<?php

function unzip($file){
$zip=zip_open(realpath(".")."/".$file);
if(!$zip) {return("Unable to proccess file '{$file}'");}
$e='';
while($zip_entry=zip_read($zip)) { $zdir=dirname(zip_entry_name($zip_entry)); $zname=zip_entry_name($zip_entry);
if(!zip_entry_open($zip,$zip_entry,"r"))
{$e.="Unable to proccess file '{$zname}'";continue;}
if(!is_dir($zdir)) mkdirr($zdir,0777);
#print "{$zdir} | {$zname} \n";
$zip_fs=zip_entry_filesize($zip_entry); if(empty($zip_fs)) continue;
$zz=zip_entry_read($zip_entry,$zip_fs);
$z=fopen($zname,"w"); fwrite($z,$zz); fclose($z); zip_entry_close($zip_entry);
}
zip_close($zip);
return($e); }
function mkdirr($pn,$mode=null) {
if(is_dir($pn)||empty($pn)) return true; $pn=str_replace(array('/', '&#…