/** * Tests the extract Method. * * @return void */ public function testExtract() { if (!JArchiveZip::isSupported()) { $this->markTestSkipped('ZIP files can not be extracted.'); } $this->object->extract(__DIR__ . '/logo.zip', $this->outputPath); $this->assertFileExists($this->outputPath . '/logo-zip.png'); }
/** * Tests the extract Method. * * @group JArchive * @return void */ public function testExtract() { if (!JArchiveZip::isSupported()) { $this->markTestSkipped('ZIP files can not be extracted.'); return; } $this->object->extract(__DIR__ . '/logo.zip', self::$outputPath); $this->assertTrue(is_file(self::$outputPath . '/logo-zip.png')); if (is_file(self::$outputPath . '/logo-zip.png')) { unlink(self::$outputPath . '/logo-zip.png'); } }
/** * Upload file. * * @param string $dest target directory to upload * @param string $field request fieldname * @param stdClass $file property where sets ouptput with this format: * $file->tmp ... request template file name * $file->name ... uploaded file name * $file->apath ... absolute path to file * $file->rpath ... real path to file * @param string $error property to set error messages * @param boolean $unpackZip wheater unpack zip files * @return boolean */ function upload($dest, $field, &$file, &$error, $unpackZip = false) { $adir = $dest; $rdir = JURI::root() . str_replace(DS, '/', $dest); $rdir = str_replace('//', '/', $dest); if (!file_exists($adir)) { if (!@mkdir($adir, 0775, true)) { $mainframe =& JFactory::getApplication(); /* @var $mainframe JApplication */ $mainframe->enqueueMessage(sprintf(JText::_('Unable create directory %s'), $adir), 'error'); return false; } } if (isset($_FILES[$field])) { $request =& $_FILES[$field]; $file = new stdClass(); $file->tmp = $request['tmp_name']; $file->name = $request['name']; if ($request['error'] == 0) { $zip = new JArchiveZip(); $data = JFile::read($file->tmp); $isZip = $zip->checkZipData($data); unset($data); if ($isZip && $unpackZip) { $tmpDir = AFile::getTmpDir(); $zip->extract($file->tmp, $tmpDir); unset($zip); $files =& JFolder::files($tmpDir, '.', true, true); $count = count($files); for ($i = 0; $i < $count; $i++) { $file->tmp = $files[$i]; $file->name = JFile::getName($file->tmp); AFile::save($file, $adir, $rdir); } JFolder::delete($tmpDir); return true; } else { unset($zip); return AFile::save($file, $adir, $rdir); } } } return false; }