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.p
hp.net/manual/en/ref.zip.php
Edit -- https://master
.php.net/note/edit/74847
Del: integrated -- h
ttps://master.php.net/note/delete/74847/integrated
Del: useless -- http
s://master.php.net/note/delete/74847/useless
Del: bad code -- htt
ps://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 -- http
s://master.php.net/note/delete/74847/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/74847
Reject -- https://mast
er.php.net/note/reject/74847
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|