public function testDecompressWillThrowExceptionWhenDecompressingWithNoTarget() { $filter = new ZipCompression(array('archive' => dirname(__DIR__) . '/_files/compressed.zip', 'target' => dirname(__DIR__) . '/_files/_compress')); $content = $filter->compress('compress me'); $this->assertEquals(dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'compressed.zip', $content); $filter = new ZipCompression(array('archive' => dirname(__DIR__) . '/_files/compressed.zip', 'target' => dirname(__DIR__) . '/_files/_compress')); $content = $filter->decompress($content); $this->assertEquals(dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR, $content); $content = file_get_contents(dirname(__DIR__) . '/_files/_compress'); $this->assertEquals('compress me', $content); }
public function downloadallAction() { $pids = $this->params('pids'); if ($pids != '') { $zip = new Zip(); $parent_dir = sys_get_temp_dir() . "/CCDA_" . time(); if (!is_dir($parent_dir)) { mkdir($parent_dir, true); chmod($parent_dir, 0777); } $arr = explode('|', $pids); foreach ($arr as $row) { $pid = $row; $id = $this->getEncountermanagerTable()->getFileID($pid); $dir = $parent_dir . "/CCDA_{$id}/"; $filename = "CCDA_{$id}.xml"; if (!is_dir($dir)) { mkdir($dir, true); chmod($dir, 0777); } $content = $this->getEncountermanagerTable()->getFile($id); $f2 = fopen($dir . $filename, "w"); fwrite($f2, $content); fclose($f2); copy(dirname(__FILE__) . "/../../../../../public/css/CDA.xsl", $dir . "CDA.xsl"); } $zip_dir = sys_get_temp_dir() . "/"; $zip_name = "CCDA.zip"; $zip->setArchive($zip_dir . $zip_name); $zip->compress($parent_dir); ob_clean(); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename={$zip_name}"); header("Content-Type: application/download"); header("Content-Transfer-Encoding: binary"); readfile($zip_dir . $zip_name); exit; } }
/** * @group 6026 * * @covers \Zend\Filter\Compress\Zip::decompress */ public function testDecompressWhenNoArchieveInClass() { if (!constant('TESTS_ZEND_FILTER_COMPRESS_ZIP_ENABLED')) { $this->markTestSkipped('ZIP compression tests are currently disabled'); } $filter = new ZipCompression(array('archive' => $this->tmp . '/compressed.zip', 'target' => $this->tmp . '/_compress')); $content = $filter->compress('compress me'); $this->assertEquals($this->tmp . DIRECTORY_SEPARATOR . 'compressed.zip', $content); $filter = new ZipCompression(array('target' => $this->tmp . '/_compress')); $content = $filter->decompress($content); $this->assertEquals($this->tmp . DIRECTORY_SEPARATOR, $content); $content = file_get_contents($this->tmp . '/_compress'); $this->assertEquals('compress me', $content); }