mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-11 09:35:00 +00:00
add method for zipping files instead of using zip command
This commit is contained in:
parent
658d00fe42
commit
f453cac8d2
|
@ -190,6 +190,61 @@ class SeedDMS_Extension_Mgr {
|
|||
return $extensions;
|
||||
} /* }}} */
|
||||
|
||||
static protected function Zip($source, $destination, $include_dir = false) { /* {{{ */
|
||||
|
||||
if (!extension_loaded('zip') || !file_exists($source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_exists($destination)) {
|
||||
unlink ($destination);
|
||||
}
|
||||
|
||||
$zip = new ZipArchive();
|
||||
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
|
||||
return false;
|
||||
}
|
||||
$source = str_replace('\\', '/', realpath($source));
|
||||
|
||||
if (is_dir($source) === true) {
|
||||
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
if ($include_dir) {
|
||||
$arr = explode("/",$source);
|
||||
$maindir = $arr[count($arr)- 1];
|
||||
|
||||
$source = "";
|
||||
for ($i=0; $i < count($arr) - 1; $i++) {
|
||||
$source .= '/' . $arr[$i];
|
||||
}
|
||||
|
||||
$source = substr($source, 1);
|
||||
|
||||
$zip->addEmptyDir($maindir);
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file = str_replace('\\', '/', $file);
|
||||
|
||||
// Ignore "." and ".." folders
|
||||
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
|
||||
continue;
|
||||
|
||||
$file = realpath($file);
|
||||
|
||||
if (is_dir($file) === true) {
|
||||
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
|
||||
} else if (is_file($file) === true) {
|
||||
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
|
||||
}
|
||||
}
|
||||
} else if (is_file($source) === true) {
|
||||
$zip->addFromString(basename($source), file_get_contents($source));
|
||||
}
|
||||
|
||||
return $zip->close();
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Create zip archive of an extension
|
||||
*
|
||||
|
@ -203,8 +258,11 @@ class SeedDMS_Extension_Mgr {
|
|||
|
||||
$tmpfile = $this->cachedir."/".$extname."-".$version.".zip";
|
||||
|
||||
$cmd = "cd ".$this->extdir."/".$extname."; zip -r ".$tmpfile." .";
|
||||
exec($cmd);
|
||||
if(!SeedDMS_Extension_Mgr::Zip($this->extdir."/".$extname, $tmpfile)) {
|
||||
return false;
|
||||
}
|
||||
// $cmd = "cd ".$this->extdir."/".$extname."; zip -r ".$tmpfile." .";
|
||||
// exec($cmd);
|
||||
|
||||
return $tmpfile;
|
||||
} /* }}} */
|
||||
|
|
Loading…
Reference in New Issue
Block a user