note 31059 deleted from ref.zip by alindeman

From: Date: Tue, 08 Apr 2003 20:36:44 +0000
Subject: note 31059 deleted from ref.zip by alindeman
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-46373@lists.php.net to get a copy of this message
If you just want to unzip everything of a zip file in a directory (and create unexisting directories), let's try this: function unzip($file, $path) { $zip = zip_open($file); if ($zip) { while ($zip_entry = zip_read($zip)) { if (zip_entry_filesize($zip_entry) > 0) { // str_replace must be used under windows to convert "/" into "\" $complete_path = $path.str_replace('/','\\',dirname(zip_entry_name($zip_entry))); $complete_name = $path.str_replace ('/','\\',zip_entry_name($zip_entry)); if(!file_exists($complete_path)) { $tmp = ''; foreach(explode('\\',$complete_path) AS $k) { $tmp .= $k.'\\'; if(!file_exists($tmp)) { mkdir($tmp, 0777); } } } if (zip_entry_open($zip, $zip_entry, "r")) { $fd = fopen($complete_name, 'w'); fwrite($fd, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry))); fclose($fd); zip_entry_close($zip_entry); } } } zip_close($zip); } } To use this function: unzip('c:\\file.zip','c:\\temp\\'); // BE CAREFULL: second argument *MUST* finish by a "\" ! ("/" under *nix) Patrick

« previous php.notes (#46373) next »