Exemplo n.º 1
0
 /**
  * Zip Backup folder
  */
 function _backupFolder()
 {
     global $option, $mainframe;
     if (!$this->_backup) {
         return;
     }
     $zipname = uniqid('backup_') . '.zip';
     if (!JFolder::exists(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup')) {
         JFolder::create(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup');
     }
     $zipdest = JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup' . DS . $zipname;
     $files = JFolder::files($this->_backup, '.', true, true);
     $fileinfos = array();
     for ($i = 0; $i < count($files); $i++) {
         $fileinfos[$i]['data'] = JFile::read($files[$i]);
         $fileinfos[$i]['name'] = str_replace($this->_backup . DS, '', $files[$i]);
     }
     $i = count($fileinfos);
     $fileinfos[$i]['data'] = JFile::read($this->_xmlname);
     $fileinfos[$i]['name'] = str_replace(dirname($this->_xmlname) . DS, '', $this->_xmlname);
     $azip = new JArchiveZip();
     $azip->create($zipdest, $fileinfos);
     JFile::write(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup' . DS . 'backup.php', '<?php defined(\'_JEXEC\') or die( \'Restricted access\' ); $urlbackup= \'' . $zipdest . '\'; ?>');
 }
Exemplo n.º 2
0
 /**
  * get file zip
  *
  */
 function export()
 {
     $path_base = JPATH_COMPONENT_SITE . DS . 'resource';
     if (JFolder::exists($path_base)) {
         JFolder::delete($path_base);
     }
     JFolder::create($path_base);
     $content = $this->getXML();
     $date = JFactory::getDate();
     $date = $date->toFormat('%Y_%m_%d_%H_%M_%S');
     $filename = 'YRM_resources_' . $date;
     $path_file = $path_base . DS . $filename;
     $xml_file = $path_file . '.xml';
     JFile::write($xml_file, $content);
     $fileinfos = array();
     $fileinfos[0]['data'] = JFile::read($xml_file);
     $fileinfos[0]['name'] = 'resource.xml';
     require_once JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'filesystem' . DS . 'archive' . DS . 'zip.php';
     $azip = new JArchiveZip();
     $azip->create($path_file . '.zip', $fileinfos);
     header("Pragma: public");
     header("Expires: 0");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Cache-Control: public");
     header("Content-Description: File Transfer");
     header("Content-Type: application/zip");
     header("Content-Disposition: attachment; filename=" . basename($path_file . ".zip") . ";");
     header("Content-Transfer-Encoding: binary");
     header("Content-Length: " . filesize($path_file . ".zip"));
     @readfile($path_file . ".zip");
     exit;
 }