function unzip_content() { $zip = new ZipArchive(); if (file_exists('application.zip')) { $res = $zip->open('application.zip'); if ($res === TRUE) { echo '<p>Unzipped Application <i class="fa fa-check-circle-o"></i></p>'; $zip->extractTo('./'); $zip->close(); unlink('application.zip'); } else { echo '<p>Could not unzip application.zip <i class="fa fa-times-circle-o"></i></p>'; } } else { echo '<p>Application already unzipped <i class="fa fa-check-circle-o"></i></p>'; } new_line(); if (file_exists('content.zip')) { $res = $zip->open('content.zip'); if ($res === TRUE) { echo '<p>Unzipped Content <i class="fa fa-check-circle-o"></i></p>'; $zip->extractTo('./'); $zip->close(); unlink('content.zip'); } else { echo '<p>Could not unzip content.zip <i class="fa fa-times-circle-o"></i></p>'; } } else { echo '<p>Content already unzipped <i class="fa fa-check-circle-o"></i></p>'; } new_line(); }
/** * Upload component * * @requires component package file, * * @return bool; */ public function upload() { $archive = new ZipArchive(); $data_dir = ossn_get_userdata('tmp/components'); if (!is_dir($data_dir)) { mkdir($data_dir, 0755, true); } $zip = $_FILES['com_file']; $newfile = "{$data_dir}/{$zip['name']}"; if (move_uploaded_file($zip['tmp_name'], $newfile)) { if ($archive->open($newfile) === TRUE) { $archive->extractTo($data_dir); $archive->close(); $validate = pathinfo($zip['name'], PATHINFO_FILENAME); if (is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) { $archive->open($newfile); $archive->extractTo(ossn_route()->com); $archive->close(); $this->newCom($validate); OssnFile::DeleteDir($data_dir); return true; } } } return false; }
/** * @param string $to - path where the archive should be extracted to * @return bool */ public function extract($to) { $r = false; $ext = SPFs::getExt($this->_filename); switch ($ext) { case 'zip': $zip = new ZipArchive(); if ($zip->open($this->_filename) === true) { SPException::catchErrors(SPC::WARNING); try { $zip->extractTo($to); $zip->close(); $r = true; } catch (SPException $x) { $t = Sobi::FixPath(Sobi::Cfg('fs.temp') . DS . md5(microtime())); SPFs::mkdir($t, 0777); $dir = SPFactory::Instance('base.fs.directory', $t); if ($zip->extractTo($t)) { $zip->close(); $dir->moveFiles($to); $r = true; } SPFs::delete($dir->getPathname()); } SPException::catchErrors(0); } break; } return $r; }
/** * Upload component * * @requires component package file, * * @return bool; */ public function upload() { $archive = new ZipArchive(); $data_dir = ossn_get_userdata('tmp/components'); if (!is_dir($data_dir)) { mkdir($data_dir, 0755, true); } $zip = $_FILES['com_file']; $newfile = "{$data_dir}/{$zip['name']}"; if (move_uploaded_file($zip['tmp_name'], $newfile)) { if ($archive->open($newfile) === TRUE) { $archive->extractTo($data_dir); //make community components works on installer #394 $validate = $archive->statIndex(0); $validate = str_replace('/', '', $validate['name']); $archive->close(); if (is_dir("{$data_dir}/{$validate}") && is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) { $archive->open($newfile); $archive->extractTo(ossn_route()->com); $archive->close(); $this->newCom($validate); OssnFile::DeleteDir($data_dir); return true; } } } return false; }
private function extractArchive() { $this->archive->close(); $this->archive->open($this->archive_path); $this->archive->extractTo($this->extraction_path); $this->archive->close(); }
/** * Validate file * * @param array $file * @param int $max_file_size MB * @param string $allowed_file_extension * @return bool TRUE if valid ot FALSE if else */ public static function fileValid($file, $max_file_size, $allowed_file_extension) { // Dependencies test if (!isset($file['tmp_name']) || !isset($file['name'])) { return false; } else { if (empty($file['tmp_name']) || empty($file['name'])) { return false; } else { // Common test if (mb_strtolower($allowed_file_extension) != @pathinfo(self::_extensionPrepare($file['name']), PATHINFO_EXTENSION)) { return false; } else { if ($max_file_size < @filesize($file['tmp_name']) / 1000000) { return false; } } // Extension test if (mb_strtolower($allowed_file_extension) == 'zip') { $zip = new ZipArchive(); if (true !== $zip->open($file['tmp_name'], ZipArchive::CHECKCONS)) { $zip->close(); return false; } $zip->close(); } } } return true; }
public function downloaded() { $messagebox = new QMessageBox(); if ($this->progressBar->value != $this->progressBar->maximum) { $this->hide(); $messagebox->critical(0, tr('PQCreator error'), tr('Error download PQPack! :-( Please, try later...'), tr('Quit')); qApp::quit(); } $this->textEdit->html .= "\n" . tr('Writing in file...'); file_put_contents($this->tempFilePath, $this->downloader->downloadedData()); $this->textEdit->html .= "\n" . sprintf(tr('Unzip data in `%s`'), $this->destinationDir); $zip = new ZipArchive(); if ($zip->open($this->tempFilePath) === TRUE) { if (!mkdir($this->destinationDir)) { $this->hide(); $messagebox->critical(0, tr('PQCreator error'), sprintf(tr('Error creating directory `%s`!'), $this->destinationDir), tr('Quit')); $zip->close(); qApp::quit(); } $zip->extractTo($this->destinationDir); $zip->close(); $this->textEdit->html .= "\n<b>" . tr('Done!') . '</b>'; $this->button->enabled = true; $messagebox->free(); unset($messagebox); qApp::beep(); return; } $this->hide(); $messagebox->critical(0, tr('PQCreator error'), sprintf(tr('Error unzip PQPack package `%s`!'), $this->tempFilePath), tr('Quit')); qApp::quit(); }
/** * Closes the archive */ protected function closeArchive() { if ($this->zip) { $this->zip->close(); $this->zip = null; } }
public function tearDown() { $this->zip->close(); $this->archive->cleanUp(); //`rm -rf $this->tmp_dir/import_project_*`; parent::tearDown(); }
/** * Closes the reader. To be used after reading the file. * * @return void */ protected function closeReader() { if ($this->zip) { $this->zip->close(); } if ($this->sharedStringsHelper) { $this->sharedStringsHelper->cleanup(); } }
/** * Finalize the xlsx file. * * @param resource $output */ public function finalize($output) { $zipFileUrl = sys_get_temp_dir() . '/' . uniqid(); $this->fillZipWithFileContents($zipFileUrl); if (!$this->zip->close()) { throw new \RuntimeException('Failed to close zip file!'); } $this->copyToOutputAndCleanup($output, $zipFileUrl); }
/** * @return string */ public function finishAndGetDocument() { $content = $this->create(); $this->zip->deleteName('content.xml'); $this->zip->addFromString('content.xml', $content); $this->zip->close(); $content = file_get_contents($this->tmpZipFile); unlink($this->tmpZipFile); return $content; }
/** * Saves file * * @param $filename * * @throws \Exception */ public function save($filename) { if (isset($this->contents)) { $this->zip->addFromString('word/document.xml', $this->contents); } $this->zip->close(); $res = @rename($this->tempFilename, $filename); if (!$res) { throw new \Exception("Unable to save file"); } }
protected function setUp() { if (!extension_loaded('zip')) { $this->markTestSkipped('The zip extension is not available'); } $this->zipFile = new \ZipArchive(); $this->zipFile->open($this->zipFilename, \ZipArchive::CREATE); $this->zipFile->addFromString($this->filename, $this->fileContents); $this->zipFile->close(); $this->collection = new ResourceCollection([new FileResource(FileTransport::create($this->zipFilename))]); }
private function load($file) { if (file_exists($file)) { $zip = new ZipArchive(); if ($zip->open($file) === true) { //attempt to load styles: if (($styleIndex = $zip->locateName('word/styles.xml')) !== false) { $stylesXml = $zip->getFromIndex($styleIndex); $xml = simplexml_load_string($stylesXml); $namespaces = $xml->getNamespaces(true); $children = $xml->children($namespaces['w']); foreach ($children->style as $s) { $attr = $s->attributes('w', true); if (isset($attr['styleId'])) { $tags = array(); $attrs = array(); foreach (get_object_vars($s->rPr) as $tag => $style) { $att = $style->attributes('w', true); switch ($tag) { case "b": $tags[] = 'strong'; break; case "i": $tags[] = 'em'; break; case "color": //echo (String) $att['val']; $attrs[] = 'color:#' . $att['val']; break; case "sz": $attrs[] = 'font-size:' . $att['val'] . 'px'; break; } } $styles[(string) $attr['styleId']] = array('tags' => $tags, 'attrs' => $attrs); } } $this->styles = $styles; } if (($index = $zip->locateName('word/document.xml')) !== false) { // If found, read it to the string $data = $zip->getFromIndex($index); // Close archive file $zip->close(); return $data; } $zip->close(); } else { $this->errors[] = 'Could not open file.'; } } else { $this->errors[] = 'File does not exist.'; } }
function merge($data, $outputPath = null) { //open the Archieve to a temp folder $this->workingDir = sys_get_temp_dir() . "/DocxTemplating"; if (!file_exists($this->workingDir)) { mkdir($this->workingDir, 0777, true); } $workingFile = tempnam($this->workingDir, ''); if ($workingFile === FALSE || !copy($this->template, $workingFile)) { throw new Exception("Error in initializing working copy of the template"); } $this->workingDir = $workingFile . "_"; $zip = new ZipArchive(); if ($zip->open($workingFile) === TRUE) { $zip->extractTo($this->workingDir); $zip->close(); } else { throw new Exception('Failed to extract Template'); } if (!file_exists($this->workingDir)) { throw new Exception('Failed to extract Template'); } $filesToParse = array(array("name" => "word/document.xml", "required" => true), array("name" => "word/header1.xml"), array("name" => "word/header2.xml"), array("name" => "word/header3.xml"), array("name" => "word/footer1.xml"), array("name" => "word/footer2.xml"), array("name" => "word/footer3.xml"), array("name" => "word/footnotes.xml"), array("name" => "word/endnotes.xml")); foreach ($filesToParse as $fileToParse) { if (isset($fileToParse["required"]) && !file_exists($this->workingDir . '/' . $fileToParse["name"])) { throw new Exception("Can not merge, Template is corrupted"); } if (file_exists($this->workingDir . '/' . $fileToParse["name"])) { $this->mergeFile($this->workingDir . '/' . $fileToParse["name"], $data); } } // once merge is happened , zip the working directory and rename $mergedFile = $this->workingDir . '/output.docx'; if ($zip->open($mergedFile, ZipArchive::CREATE) === FALSE) { throw new Exception("Error in creating output"); } // Create recursive directory iterator $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->workingDir, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::LEAVES_ONLY); foreach ($files as $name => $file) { $name = substr($name, strlen($this->workingDir . "/")); $zip->addFile($file->getRealPath(), $name); //echo "\n".$name ." : ".$file->getRealPath(); } $zip->close(); //once merged file is available copy it to $outputPath or write as downloadable file if (isset($outputPath)) { copy($mergedFile, $outputPath); } else { } // remove workingDir and workingFile unlink($workingFile); $this->deleteDir($this->workingDir); }
public function extract($archive, $directory, $options = array()) { $zip = new \ZipArchive(); if (!$zip->open($archive)) { throw new OperationFailedException("could not open zip archive {$archive}"); } if (!$zip->extractTo($directory)) { $zip->close(); throw new OperationFailedException("could not extract zip archive to {$directory}"); } $zip->close(); }
function extractZip($src, $dest) { $zip = new ZipArchive(); if ($zip->open($src) === true) { if (!$zip->extractTo($dest)) { $zip->close(); return false; } $zip->close(); return true; } return false; }
/** * _unzipFile * * @return bool **/ public function _unzipFile() { // local file name //$downloadFilePath = $this->_getDownloadFilePath(); $downloadDirPath = realpath($this->Xupdate->params['temp_path']); $downloadFilePath = $this->Xupdate->params['temp_path'] . '/' . $this->target_key . '.zip'; $exploredDirPath = realpath($downloadDirPath . '/' . $this->target_key); if (empty($downloadFilePath)) { $this->_set_error_log('getDownloadFilePath not found error in: ' . $this->_getDownloadFilePath()); return false; } if (!chdir($exploredDirPath)) { $this->_set_error_log('chdir error in: ' . $exploredDirPath); return false; //chdir error } try { if (!class_exists('ZipArchive')) { throw new Exception('ZipArchive class not found fail', 1); } } catch (Exception $e) { $this->_set_error_log($e->getMessage()); return false; } $zip = new ZipArchive(); try { $result = $zip->open($downloadFilePath); if ($result !== true) { throw new Exception('ZipArchive open fail ' . $downloadFilePath, 2); } } catch (Exception $e) { $zip_open_error_arr = array(ZIPARCHIVE::ER_EXISTS => 'ER_EXISTS', ZIPARCHIVE::ER_INCONS => 'ER_INCONS', ZIPARCHIVE::ER_INVAL => 'ER_INVAL', ZIPARCHIVE::ER_MEMORY => 'ER_MEMORY', ZIPARCHIVE::ER_NOENT => 'ER_NOENT', ZIPARCHIVE::ER_NOZIP => 'ER_NOZIP', ZIPARCHIVE::ER_OPEN => 'ER_OPEN', ZIPARCHIVE::ER_READ => 'ER_READ', ZIPARCHIVE::ER_SEEK => 'ER_SEEK'); $this->_set_error_log($e->getMessage() . (in_array($result, $zip_open_error_arr) ? f : 'undefine')); return false; } //$zip->extractTo('./'); try { $result = $zip->extractTo('./'); if ($result !== true) { throw new Exception('extractTo fail ', 3); } } catch (Exception $e) { $this->_set_error_log($e->getMessage()); $zip->close(); return false; } $zip->close(); $this->Ftp->appendMes('explored in: ' . $exploredDirPath . '<br />'); $this->content .= 'explored in: ' . $exploredDirPath . '<br />'; return true; }
/** * Metodo utilizzato per estrarre i tracciati dati e immagini * nella cartella import */ function extractFileIntoFolder() { $zip = new \ZipArchive(); $res = $zip->open(FOLDER_IMPORT_ROOT . FILE_ERP_DATA); if ($res === TRUE) { $zip->extractTo(FOLDER_UNZIP); $zip->close(); } $res2 = $zip->open(FOLDER_IMPORT_ROOT . FILE_ERP_IMG); if ($res2 === TRUE) { $zip->extractTo(FOLDER_UNZIP); $zip->close(); } }
public function unzip($filePath, $target) { if (!extension_loaded('zip')) { Mage::throwException($this->__('Zip PHP extension is not installed')); } $zip = new ZipArchive(); if (!$zip->open($filePath)) { Mage::throwException($this->__('Invalid or corrupted zip file')); } if (!$zip->extractTo($target)) { $zip->close(); Mage::throwException($this->__('Errors during unpacking zip file. Please check destination write permissions: %s', $target)); } $zip->close(); }
public function display($cachable = false, $urlparams = false) { JRequest::setVar('view', JRequest::getCmd('view', 'Orphans')); if (isset($_POST['_orphanaction']) && $_POST['_orphanaction'] == "zipIt") { $file = tempnam("tmp", "zip"); $zip = new ZipArchive(); $zip->open($file, ZipArchive::OVERWRITE); foreach ($_POST['tozip'] as $_file) { $zip->addFile(JPATH_ROOT . "/" . $_file, $_file); } $zip->close(); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filename="orphans.zip"'); readfile($file); unlink($file); die; } else { if (isset($_POST['_orphanaction']) && $_POST['_orphanaction'] == "delete" && isset($_POST['_confirmAction'])) { foreach ($_POST['tozip'] as $_file) { unlink(JPATH_ROOT . "/" . $_file); } } } // call parent behavior parent::display($cachable); }
public function zipTranslations($groups) { $zip_name = tempnam("Translations_" . time(), "zip"); // Zip name $this->zipExporting = new ZipArchive(); $this->zipExporting->open($zip_name, ZipArchive::OVERWRITE); if (!is_array($groups)) { if ($groups === '*') { $groups = $this->translation->whereNotNull('value')->select(DB::raw('DISTINCT `group`'))->get('group'); foreach ($groups as $group) { // Stuff with content $this->exportTranslations($group->group, 0); } } else { // Stuff with content $this->exportTranslations($groups, 0); } } else { foreach ($groups as $group) { // Stuff with content $this->exportTranslations($group, 0); } } $this->zipExporting->close(); $this->zipExporting = null; return $zip_name; }
public function writeToFile($filename) { @unlink($filename); //if the zip already exists, overwrite it $zip = new ZipArchive(); if (empty($this->sheets_meta)) { self::log("Error in " . __CLASS__ . "::" . __FUNCTION__ . ", no worksheets defined."); return; } if (!$zip->open($filename, ZipArchive::CREATE)) { self::log("Error in " . __CLASS__ . "::" . __FUNCTION__ . ", unable to create zip."); return; } $zip->addEmptyDir("docProps/"); $zip->addFromString("docProps/app.xml", self::buildAppXML()); $zip->addFromString("docProps/core.xml", self::buildCoreXML()); $zip->addEmptyDir("_rels/"); $zip->addFromString("_rels/.rels", self::buildRelationshipsXML()); $zip->addEmptyDir("xl/worksheets/"); foreach ($this->sheets_meta as $sheet_meta) { $zip->addFile($sheet_meta['filename'], "xl/worksheets/" . $sheet_meta['xmlname']); } if (!empty($this->shared_strings)) { $zip->addFile($this->writeSharedStringsXML(), "xl/sharedStrings.xml"); //$zip->addFromString("xl/sharedStrings.xml", self::buildSharedStringsXML() ); } $zip->addFromString("xl/workbook.xml", self::buildWorkbookXML()); $zip->addFile($this->writeStylesXML(), "xl/styles.xml"); //$zip->addFromString("xl/styles.xml" , self::buildStylesXML() ); $zip->addFromString("[Content_Types].xml", self::buildContentTypesXML()); $zip->addEmptyDir("xl/_rels/"); $zip->addFromString("xl/_rels/workbook.xml.rels", self::buildWorkbookRelsXML()); $zip->close(); }
/** * test export data */ public function testExportData() { $dao = new BackupMySQLDAO(); $export_file = $dao->export(); $this->assertTrue( file_exists($export_file) ); $zip_stats = stat($export_file); $this->assertTrue($zip_stats['size'] > 0); $za = new ZipArchive(); $za->open($export_file); $zip_files = array(); for ($i=0; $i<$za->numFiles;$i++) { $zfile = $za->statIndex($i); $zip_files[$zfile['name']] = $zfile['name']; } //verify we have create table file $this->assertTrue($zip_files["create_tables.sql"]); $za->close(); $q = "show tables"; $q2 = "show create table "; $stmt = $this->pdo->query($q); // verify we have all table files while($data = $stmt->fetch(PDO::FETCH_ASSOC)) { foreach($data as $key => $value) { $zfile = '/' . $value .'.txt'; $this->assertTrue($zip_files[$zfile]); } } }
public function downloadAction() { $squadID = $this->params('id', 0); $squadRepo = $this->getEntityManager()->getRepository('Frontend\\Squads\\Entity\\Squad'); /** @var Squad $squadEntity */ $squadEntity = $squadRepo->findOneBy(array('user' => $this->identity(), 'id' => $squadID)); if (!$squadEntity) { $this->flashMessenger()->addErrorMessage('Squad not found'); return $this->redirect('frontend/user/squads'); } $fileName = 'squad_file_pack_armasquads_' . $squadID; $zipTmpPath = tempnam(ini_get('upload_tmp_dir'), $fileName); $zip = new \ZipArchive(); $zip->open($zipTmpPath, \ZipArchive::CHECKCONS); if (!$zip) { $this->flashMessenger()->addErrorMessage('Squad Package Download currently not possible'); return $this->redirect('frontend/user/squads'); } $zip->addFromString('squad.xml', file_get_contents('http://' . $_SERVER['SERVER_NAME'] . $this->url()->fromRoute('frontend/user/squads/xml', array('id' => $squadEntity->getPrivateID())))); if ($squadEntity->getSquadLogoPaa()) { $zip->addFile(ROOT_PATH . $squadEntity->getSquadLogoPaa(), basename($squadEntity->getSquadLogoPaa())); } $zip->addFromString('squad.dtd', file_get_contents(realpath(__DIR__ . '/../../../../view/squads/xml/') . '/squad.dtd')); //$zip->addFromString('squad.xsl',file_get_contents(realpath(__DIR__ . '/../../../../view/squads/xml/').'/squad.xsl')); $zip->close(); header('Content-Type: application/octet-stream'); header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=\"" . basename($fileName) . ".zip\""); readfile($zipTmpPath); sleep(1); @unlink($zipTmpPath); die; }
private static function getZippedFile($filename) { if(!self::zipModuleLoaded()) { throw new WURFL_WURFLException("The Zip extension is not loaded. Load the extension or use the flat wurfl.xml file"); } $tmpDir = sys_get_temp_dir(); $zip = new ZipArchive(); if ($zip->open($filename)!==TRUE) { exit("cannot open <$filename>\n"); } $zippedFile = $zip->statIndex(0); $wurflFile = $zippedFile['name']; //$wurflFile = md5(uniqid(rand(), true)); //$zip->extractTo($tmpDir, $wurflFile); $zip->extractTo($tmpDir); $zip->close(); return $tmpDir . '/' .$wurflFile; }
/** * 程序文件列表 */ public function actionIndex() { if (isset($_POST['id'])) { $files = $_POST['id']; if ($files) { //提交打包 $zip = new ZipArchive(); $name = 'yiifcmsBAK_' . date('YmdHis', time()) . '.zip'; $zipname = WWWPATH . '/' . $name; //创建一个空的zip文件 if ($zip->open($zipname, ZipArchive::OVERWRITE)) { foreach ((array) $files as $file) { if (is_dir($file)) { //递归检索文件 $allfiles = Helper::scanfDir($file, true); foreach ((array) $allfiles['files'] as $v) { $zip->addFile(WWWPATH . '/' . $v, $v); } } else { $zip->addFile(WWWPATH . '/' . $file, $file); } } $zip->close(); //开始下载 Yii::app()->request->sendFile($name, file_get_contents($zipname), '', false); //下载完成后要进行删除 @unlink($zipname); } else { throw new CHttpException('404', 'Failed'); } } } else { $files = Helper::scanfDir(WWWPATH); asort($files['dirs']); asort($files['files']); $files = array_merge($files['dirs'], $files['files']); $listfiles = array(); foreach ($files as $file) { $tmpfilename = explode('/', $file); $filename = end($tmpfilename); if (is_dir($file)) { $allfiles = Helper::scanfDir($file, true); if ($allfiles['files']) { $filesize = 0; foreach ((array) $allfiles['files'] as $val) { $filesize += filesize($val); } } $listfiles[$filename]['type'] = 'dir'; } else { $filesize = filesize($file); $listfiles[$filename]['type'] = 'file'; } $listfiles[$filename]['id'] = $filename; $listfiles[$filename]['size'] = Helper::byteFormat($filesize); $listfiles[$filename]['update_time'] = filemtime($filename); } } $this->render('index', array('listfiles' => $listfiles)); }
function zipFile($source, $destination, $flag = '') { if (!extension_loaded('zip') || !file_exists($source)) { return false; } $zip = new ZipArchive(); if (!$zip->open($destination, ZIPARCHIVE::CREATE)) { return false; } $source = str_replace('\\', '/', realpath($source)); if ($flag) { $flag = basename($source) . '/'; //$zip->addEmptyDir(basename($source) . '/'); } if (is_dir($source) === true) { $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file) { $file = str_replace('\\', '/', realpath($file)); if (is_dir($file) === true) { $zip->addEmptyDir(str_replace($source . '/', '', $flag . $file . '/')); } else { if (is_file($file) === true) { $zip->addFromString(str_replace($source . '/', '', $flag . $file), file_get_contents($file)); } } } } else { if (is_file($source) === true) { $zip->addFromString($flag . basename($source), file_get_contents($source)); } } echo "Successfully Ziped Folder"; header('Location:admin/dashboard/admin_dashboard'); return $zip->close(); }
public function route_makeRequest() { $type = pluralize(strip_tags($_GET['type'])); set_time_limit(0); $fp = fopen("../{$type}/latest.zip", 'w+'); $url = str_replace(" ", "%20", strip_tags($_GET['url'])); $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $fp); # write curl response to file curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); fclose($fp); $zip = new ZipArchive(); if ($zip->open("../{$type}/latest.zip") == true) { mkdir("../{$type}/latest", 0777); $zip->extractTo("../{$type}/latest"); $zip->close(); $handle = opendir("../{$type}/latest"); if ($handle) { while (($file = readdir($handle)) !== false) { if (is_dir("../{$type}/latest/{$file}")) { if ($file != '.' and $file != '..') { rename("../{$type}/latest/{$file}", "../{$type}/{$file}"); } } } } $this->rrmdir("../{$type}/latest"); unlink("../{$type}/latest.zip"); $this->rrmdir("../{$type}/__MACOSX"); } Flash::notice(__("Extension downloaded successfully.", "extension_manager"), "/admin/?action=extend_manager"); }