/** * @param InputInterface $input * @param OutputInterface $output * * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { $source = $input->getArgument('source'); if ('/' !== $source[0]) { $source = getcwd() . '/' . $source; } if (false === is_file($source)) { $output->writeln(sprintf('Cannot extract from <%s>', $source)); exit; } $target = $input->getArgument('target'); if (true === empty($target)) { $target = getcwd(); } elseif ('/' !== $target[0]) { $target = getcwd() . '/' . $target; } if (false === is_dir($target)) { $output->writeln(sprintf('Cannot extract to <%s>', $target)); exit; } $zip = new ZipArchive64(); if (false === $zip->open($source)) { $output->writeln(sprintf('Cannot open <%s>', $source)); exit; } if (false === $zip->extractTo($target)) { $output->writeln(sprintf('Cannot extract to <%s>', $target)); exit; } $zip->close(); }
public function testCreateZipArchive() { $zip = new ZipArchive64(); $zip->open('Tests/res/test.zip', ZipArchive::OVERWRITE); foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('Tests/res/example')) as $filename) { if (true === $filename->isDir()) { continue; } $zip->addFile($filename); } $zip->close(); $zip = new ZipArchive64(); $zip->open('Tests/res/test.zip'); $zip->extractTo('Tests/res/result'); $zip->close(); }