note 74847 added to ref.zip

From: Date: Mon, 30 Apr 2007 19:55:05 +0000
Subject: note 74847 added to ref.zip
Groups: php.notes 
Request: Send a blank email to php-notes+get-125993@lists.php.net to get a copy of this message
Hi, all There are lot of functions given below which etracts files, but what they lack is setting file permissions. On some servers file permissions are very important and the script cease to work after creating first directory, So I have added chmod to the code. There is only one limitation to the code, files without file extension are neither treated as files or directories so they are not chmoded, anyway this does not affect the code. Hope this helps. <?php function unpackZip($dir,$file) { if ($zip = zip_open($dir.$file.".zip")) { if ($zip) { mkdir($dir.$file); chmod($dir.$file, 0777); while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip,$zip_entry,"r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); $dir_name = dirname(zip_entry_name($zip_entry)); if ($dir_name != ".") { $dir_op = $dir.$file."/"; foreach ( explode("/",$dir_name) as $k) { $dir_op = $dir_op . $k; if (is_file($dir_op)) unlink($dir_op); if (!is_dir($dir_op)) mkdir($dir_op); chmod($dir_op, 0777); $dir_op = $dir_op . "/" ; } } $fp=fopen($dir.$file."/".zip_entry_name($zip_entry),"w+"); chmod($dir.$file."/".zip_entry_name($zip_entry), 0777); fwrite($fp,$buf); fclose($fp); zip_entry_close($zip_entry); } else return false; } zip_close($zip); } } else return false; return true; } $dir = $_SERVER['DOCUMENT_ROOT']."/"."destdirectory/"; $file = 'zipfilename_without_extension'; unpackZip($dir,$file); $print = $_SERVER['DOCUMENT_ROOT']; ?> ---- Server IP: 203.199.114.50 Probable Submitter: 202.65.136.2 ---- Manual Page -- http://www.php.net/manual/en/ref.zip.php Edit -- https://master.php.net/note/edit/74847 Del: integrated -- https://master.php.net/note/delete/74847/integrated Del: useless -- https://master.php.net/note/delete/74847/useless Del: bad code -- https://master.php.net/note/delete/74847/bad+code Del: spam -- https://master.php.net/note/delete/74847/spam Del: non-english -- https://master.php.net/note/delete/74847/non-english Del: in docs -- https://master.php.net/note/delete/74847/in+docs Del: other reasons-- https://master.php.net/note/delete/74847 Reject -- https://master.php.net/note/reject/74847 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125993) next »