note 109567 added to ref.zip
| From: | Junsee dot WebDesigner at gmail dot com | Date: | Sun, 29 Jul 2012 15:32:51 +0000 |
| Subject: | note 109567 added to ref.zip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189452@lists.php.net to get a copy of this message | ||
Without stepping on toes... Beautiful code supplied by shadowbranch, all credit to him, just one
slight admendment.
Now allows the files not in a folder, in the zip file, to also be extracted.
<?php
function unzip($file){
$zip = zip_open($file);
if(is_resource($zip)){
$tree = "";
while(($zip_entry = zip_read($zip)) !== false){
echo "Unpacking ".zip_entry_name($zip_entry)."\n";
if(strpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR) !== false){
$last = strrpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR);
$dir = substr(zip_entry_name($zip_entry), 0, $last);
$file = substr(zip_entry_name($zip_entry), strrpos(zip_entry_name($zip_entry),
DIRECTORY_SEPARATOR)+1);
if(!is_dir($dir)){
@mkdir($dir, 0755, true) or die("Unable to create $dir\n");
}
if(strlen(trim($file)) > 0){
$return = @file_put_contents($dir."/".$file,
zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
if($return === false){
die("Unable to write file $dir/$file\n");
}
}
}else{
$file = substr( zip_entry_name($zip_entry), strrpos(zip_entry_name($zip_entry)) );
file_put_contents($file, zip_entry_read($zip_entry,
zip_entry_filesize($zip_entry)));
}
}
}else{
echo "Unable to open zip file\n";
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 88.81.96.222
----
Manual Page -- http://www.php.net/manual/en/ref.zip.php
Edit -- https://master.php.net/note/edit/109567
Del: integrated -- https://master.php.net/note/delete/109567/integrated
Del: useless -- https://master.php.net/note/delete/109567/useless
Del: bad code -- https://master.php.net/note/delete/109567/bad+code
Del: spam -- https://master.php.net/note/delete/109567/spam
Del: non-english -- https://master.php.net/note/delete/109567/non-english
Del: in docs -- https://master.php.net/note/delete/109567/in+docs
Del: other reasons-- https://master.php.net/note/delete/109567
Reject -- https://master.php.net/note/reject/109567
Search -- https://master.php.net/manage/user-notes.php