note 61159 added to ref.zip

From: Date: Fri, 27 Jan 2006 02:06:38 +0000
Subject: note 61159 added to ref.zip
Groups: php.notes 
Request: Send a blank email to php-notes+get-102522@lists.php.net to get a copy of this message
this function extract all files and subdirectories, you can choose verbose mode for get paths of files extracted. the function return a msg what indicate the error, if msg is OK, all is done. --- code: function unzip($dir, $file, $verbose = 0) { $dir_path = "$dir$file"; $zip_path = "$dir$file.zip"; $ERROR_MSGS[0] = "OK"; $ERROR_MSGS[1] = "Zip path $zip_path doesn't exists."; $ERROR_MSGS[2] = "Directory $dir_path for unzip the pack already exists, impossible continue."; $ERROR_MSGS[3] = "Error while opening the $zip_path file."; $ERROR = 0; if (file_exists($zip_path)) { if (!file_exists($dir_path)) { mkdir($dir_path); if (($link = zip_open($zip_path))) { while (($zip_entry = zip_read($link)) && (!$ERROR)) { if (zip_entry_open($link, $zip_entry, "r")) { $data = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); $dir_name = dirname(zip_entry_name($zip_entry)); $name = zip_entry_name($zip_entry); if ($name[strlen($name)-1] == '/') { $base = "$dir_path/"; foreach ( explode("/", $name) as $k) { $base .= "$k/"; if (!file_exists($base)) mkdir($base); } } else { $name = "$dir_path/$name"; if ($verbose) echo "extracting: $name<br>"; $stream = fopen($name, "w"); fwrite($stream, $data); } zip_entry_close($zip_entry); } else $ERROR = 4; } zip_close($link); } else $ERROR = "3"; } else $ERROR = 2; } else $ERROR = 1; return $ERROR_MSGS[$ERROR]; } --- example: $error = unzip("d:/www/dir/", "zipname", 1); echo $error; --- i hope this help you, good bye. ---- Server IP: 80.241.173.254 Probable Submitter: 85.18.14.5 ---- Manual Page -- http://www.php.net/manual/en/ref.zip.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61159 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61159&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61159&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61159&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61159&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61159&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61159&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61159&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61159&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102522) next »