note 106062 added to class.ziparchive
| From: | webmaster at sebastiangrinke dot info | Date: | Thu, 06 Oct 2011 20:30:25 +0000 |
| Subject: | note 106062 added to class.ziparchive | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183676@lists.php.net to get a copy of this message | ||
Here is a simple function which zips folders with all sub folders or only a simple file... the $data
var can be a string or an array...
public function un_zip($data,$arcpf,$mode='zip',$obj=''){
$absoluterpfad = 'YOUR_BASE_PATH';
$arcpf = $absoluterpfad.DS.$arcpf;
if(is_object($obj)==false){
$archiv = new ZipArchive();
$archiv->open($arcpf,ZipArchive::CREATE);
}else{$archiv =& $obj;}
if($mode=='zip'){
if(is_array($data)==true){
foreach($data as $dtmp){
$archiv =& un_zip($dtmp,$arcpf,'zip',&$archiv);
}
}else{
if(is_dir($data)==true){
$archiv->addEmptyDir(str_replace($absoluterpfad.DS,'',$data));
$files = scandir($data);
$bad = array('.','..');
$files = array_diff($files,$bad);
foreach($files as $ftmp){
if(is_dir($data.DS.$ftmp)==true){
$archiv->addEmptyDir(str_replace($absoluterpfad.DS,'',$data.'/'.$ftmp));
$archiv =& un_zip($data.DS.$ftmp,$arcpf,'zip',&$archiv);
}elseif(is_file($data.DS.$ftmp)==true){
$archiv->addFile($data.DS.$ftmp,str_replace($absoluterpfad.DS,'',$data.'/'.$ftmp));
}
}
}elseif(is_file($data)==true){$archiv->addFile($data,str_replace($absoluterpfad.DS,'',$data));}
}
}
if(is_object($obj)==false){$archiv->close();}
else{return $archiv;}
if($mode=='unzip'){$archiv->extractTo($data);}
}
----
Server IP: 212.124.37.9
Probable Submitter: 77.22.31.182
----
Manual Page -- http://www.php.net/manual/en/class.ziparchive.php
Edit -- https://master.php.net/note/edit/106062
Del: integrated -- https://master.php.net/note/delete/106062/integrated
Del: useless -- https://master.php.net/note/delete/106062/useless
Del: bad code -- https://master.php.net/note/delete/106062/bad+code
Del: spam -- https://master.php.net/note/delete/106062/spam
Del: non-english -- https://master.php.net/note/delete/106062/non-english
Del: in docs -- https://master.php.net/note/delete/106062/in+docs
Del: other reasons-- https://master.php.net/note/delete/106062
Reject -- https://master.php.net/note/reject/106062
Search -- https://master.php.net/manage/user-notes.php