note 85585 added to function.zip-open

From: Date: Sun, 07 Sep 2008 04:22:16 +0000
Subject: note 85585 added to function.zip-open
Groups: php.notes 
Request: Send a blank email to php-notes+get-144209@lists.php.net to get a copy of this message
If you want to simply extract a strain of a zip file, then use this func. Maybe it helps: <?php /** * This method unzips a directory within a zip-archive * * @author Florian 'x!sign.dll' Wolf * @license LGPL v2 or later * @link http://www.xsigndll.de * @link http://www.clansuite.com */ function extractZip( $zipFile = '', $dirFromZip = '' ) { define(DIRECTORY_SEPARATOR, '/'); $zipDir = getcwd() . DIRECTORY_SEPARATOR; $zip = zip_open($zipDir.$zipFile); if ($zip) { while ($zip_entry = zip_read($zip)) { $completePath = $zipDir . dirname(zip_entry_name($zip_entry)); $completeName = $zipDir . zip_entry_name($zip_entry); // Walk through path to create non existing directories // This won't apply to empty directories ! They are created further below if(!file_exists($completePath) && preg_match( '#^' . $dirFromZip .'.*#', dirname(zip_entry_name($zip_entry)) ) ) { $tmp = ''; foreach(explode('/',$completePath) AS $k) { $tmp .= $k.'/'; if(!file_exists($tmp) ) { @mkdir($tmp, 0777); } } } if (zip_entry_open($zip, $zip_entry, "r")) { if( preg_match( '#^' . $dirFromZip .'.*#', dirname(zip_entry_name($zip_entry)) ) ) { if ($fd = @fopen($completeName, 'w+')) { fwrite($fd, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry))); fclose($fd); } else { // We think this was an empty directory mkdir($completeName, 0777); } zip_entry_close($zip_entry); } } } zip_close($zip); } return true; } // The call to exctract a path within the zip file extractZip( 'clansuite.zip', 'core/filters' ); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 84.180.114.74 ---- Manual Page -- http://www.php.net/manual/en/function.zip-open.php Edit -- https://master.php.net/note/edit/85585 Del: integrated -- https://master.php.net/note/delete/85585/integrated Del: useless -- https://master.php.net/note/delete/85585/useless Del: bad code -- https://master.php.net/note/delete/85585/bad+code Del: spam -- https://master.php.net/note/delete/85585/spam Del: non-english -- https://master.php.net/note/delete/85585/non-english Del: in docs -- https://master.php.net/note/delete/85585/in+docs Del: other reasons-- https://master.php.net/note/delete/85585 Reject -- https://master.php.net/note/reject/85585 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144209) next »