note 92941 added to ref.zip

From: Date: Sat, 15 Aug 2009 16:24:09 +0000
Subject: note 92941 added to ref.zip
Groups: php.notes 
Request: Send a blank email to php-notes+get-159515@lists.php.net to get a copy of this message
very short version of function for unzipping files with folders structure: <?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('/', ''),DIRECTORY_SEPARATOR,$pn); if(is_file($pn)) {trigger_error('mkdirr() File exists', E_USER_WARNING);return false;} $next_pathname=substr($pn,0,strrpos($pn,DIRECTORY_SEPARATOR)); if(mkdirr($next_pathname,$mode)) {if(!file_exists($pn)) {return mkdir($pn,$mode);} } return false; } unzip("test.zip"); ?> have a nice day :) ---- Server IP: 64.71.164.2 Probable Submitter: 124.157.170.166 ---- Manual Page -- http://www.php.net/manual/en/ref.zip.php Edit -- https://master.php.net/note/edit/92941 Del: integrated -- https://master.php.net/note/delete/92941/integrated Del: useless -- https://master.php.net/note/delete/92941/useless Del: bad code -- https://master.php.net/note/delete/92941/bad+code Del: spam -- https://master.php.net/note/delete/92941/spam Del: non-english -- https://master.php.net/note/delete/92941/non-english Del: in docs -- https://master.php.net/note/delete/92941/in+docs Del: other reasons-- https://master.php.net/note/delete/92941 Reject -- https://master.php.net/note/reject/92941 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159515) next »