open($file,ZipArchive::CREATE|ZipArchive::OVERWRITE); foreach($structure['folders'] as $fi){ $za->addEmptyDir(substr($fi['path'], 1)); } foreach($structure['files'] as $fii){ //$za->addFromString(substr($fii['path'], 1),file_get_contents($fii['realPath'])); $za->addFile($fii['realPath'],substr($fii['path'], 1)); //if 2 much mmry consumption //$za->setCompressionName(substr($fii['path'], 1),ZipArchive::CM_STORE);//uncomment this line and $za->setCompressionName(substr($fii['path'], 1),ZipArchive::CM_DEFAULT);//comment this line //explanation //CM_DEFAULT take longer and have a better compression at cost of RAM and CPU //CM_STORE basically put all file in one without compression } $za->close(); } catch (Exception $e){ return false; } return true; } //cli_report_error('happy'); //fileguid if(!isset($_ARGUMENTS['params']['structure'])){ changeProcessState($_ARGUMENTS['guid'],-1,'missing structure',$_ARGUMENTS); cli_report_error('missing structure'); } if(($v = zipItemsRecursively($_ARGUMENTS['params']['filepath'],$_ARGUMENTS['params']['structure']))){ $ret = replaceFileWithGuid($_ARGUMENTS['params']['fileguid'],$_ARGUMENTS['params']['filepath'],$_ARGUMENTS); if($ret['error']){ $state = -1; $resp = $ret['msg']; } else { $state = 1; $resp = $_ARGUMENTS['params']['fileguid']; } changeProcessState($_ARGUMENTS['guid'],$state,$resp,$_ARGUMENTS); } else { changeProcessState($_ARGUMENTS['guid'],-1,'error while zipping structure',$_ARGUMENTS); cli_report_error('error while zipping structure'); }