protected function customExport() { $fields = array(); $query = array(); $limit = $this->request->getParam('limit'); $skip = $this->request->getParam('skip'); $limit = empty($limit) ? false : $limit; $skip = empty($skip) ? false : $skip; $path = '/tmp/'; $fileName = $this->request->getParam('file_name'); $fileName = (empty($fileName) ? $this->collection : $fileName) . '.json'; $cursor = $this->getModel()->find($this->db, $this->collection, $query, $fields, $limit, $skip); $file = new File($path, $fileName); $file->delete(); $cryptography = new Cryptography(); while ($cursor->hasNext()) { $document = $cursor->getNext(); $file->write($cryptography->arrayToJSON($document) . "\n"); } if ($this->request->getParam('text_or_save') == 'save') { if ($file->success) { if ($this->request->getParam('compression') == 'none') { $file->download(); } else { $compressFile = $this->createCompress($fileName, $file); if ($compressFile) { $file->download($compressFile); } else { $this->message->error = $file->message; return false; } } } else { $this->message->error = $file->message; return false; } } else { return file_get_contents($path . $fileName); } }
/** * Выгрузка файла конфигурации */ public function download_action($themes = array()) { $archive_name = 'config.zip'; $path = TEMP . DS . $archive_name; $zip = new Zip(array('file' => $path, 'create' => TRUE)); $zip->info(array('type' => 'config')); $zip->add(ROOT . DS . 'config' . EXT); $zip->close(); File::download($path, $archive_name, TRUE); }
/** * Backup admin */ public static function main() { $backups_path = ROOT . DS . 'backups'; // Create backup // ------------------------------------- if (Request::post('create_backup')) { if (Security::check(Request::post('csrf'))) { @set_time_limit(0); @ini_set("memory_limit", "512M"); $zip = Zip::factory(); // Add storage folder $zip->readDir(STORAGE . DS, false); // Add public folder $zip->readDir(ROOT . DS . 'public' . DS, false); // Add plugins folder $zip->readDir(PLUGINS . DS, false, null, array(PLUGINS . DS . 'box')); if ($zip->archive($backups_path . DS . Date::format(time(), "Y-m-d-H-i-s") . '.zip')) { Notification::set('success', __('Backup was created', 'backup')); } else { Notification::set('error', __('Backup was not created', 'backup')); } Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Delete backup // ------------------------------------- if (Request::get('id') == 'backup' && Request::get('delete_file')) { if (Security::check(Request::get('token'))) { if (File::delete($backups_path . DS . Request::get('delete_file'))) { Notification::set('success', __('Backup was deleted', 'backup')); } else { Notification::set('error', __('Backup was not deleted', 'backup')); } Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Download backup // ------------------------------------- if (Request::get('download')) { if (Security::check(Request::get('token'))) { File::download($backups_path . DS . Request::get('download')); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Restore backup // ------------------------------------- if (Request::get('restore')) { if (Security::check(Request::get('token'))) { $tmp_dir = ROOT . DS . 'tmp' . DS . uniqid('backup_'); if (Dir::create($tmp_dir)) { $file_locations = Zip::factory()->extract($backups_path . DS . Request::get('restore'), $tmp_dir); if (!empty($file_locations)) { Dir::copy($tmp_dir, ROOT . DS); Notification::set('success', __('Backup was restored', 'backup')); } else { Notification::set('error', __('Unzip error', 'backup')); } } else { Notification::set('error', __('Backup was not restored', 'backup')); } Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Display view View::factory('box/backup/views/backend/index')->assign('backups_list', File::scan($backups_path, '.zip'))->display(); }
/** * Выгрузка индекса в браузер * * @param type $path */ public function download_action($path) { if ($path === 'index') { $file = $this->prepareFile((array) session('admin.lang.index')); } else { $file = ROOT . DS . $path . $this->prepareFilePath(); if (!file_exists($file)) { return error(t('Файл <b>%s</b> не существует!', $file)); } } File::download($file, $this->lang . EXT); }
foreach ($_POST['map'] as $map) { $struct[] = $data['mapsDirectoryPath'] . $map; } $zipError = null; $zipFileName = 'maps.zip'; if (!Zip::create($zipFileName, $struct, $zipError)) { AdminServ::error($zipError); } else { File::download($zipFileName); AdminServLogs::add('action', 'Download packmap (' . $countMaps . ' maps)'); if ($result = File::delete($zipFileName) !== true) { AdminServ::error($result); } } } else { File::download($data['mapsDirectoryPath'] . $_POST['map'][0]); AdminServLogs::add('action', 'Download map: ' . $_POST['map'][0]); } } else { if (isset($_POST['renameMapValid']) && isset($_POST['map']) && count($_POST['map']) > 0 && isset($_POST['renameMapList']) && count($_POST['renameMapList']) > 0) { $i = 0; foreach ($_POST['renameMapList'] as $newMapName) { $result = File::rename($data['mapsDirectoryPath'] . $_POST['map'][$i], $data['mapsDirectoryPath'] . $args['directory'] . $newMapName); if ($result !== true) { AdminServ::error(Utils::t('Unable to rename the map') . ' : ' . $newMapName . ' (' . $result . ')'); break; } else { AdminServLogs::add('action', 'Rename map: ' . $_POST['map'][$i] . ' to ' . $newMapName); } $i++; }
/** * Выгрузка шестерёнок */ public function download_action($gears = array()) { if ($gears = $this->input->get('gears', $gears)) { !is_array($gears) && ($gears = explode(',', $gears)); // Если шестерёнка одна — называем архив её именем // Если шестерёнок несколько — называем архив gears $archive_name = (1 === sizeof($gears) ? end($gears) : 'gears') . '.zip'; $path = TEMP . DS . $archive_name; $zip = new Zip(array('file' => $path, 'create' => TRUE)); foreach ($gears as $gear) { $dir = GEARS . DS . $gear; // Если директория существует и шестерёнка не относится к ядру if (is_dir($dir) && !cogear()->site->gears->findByValue($gear)) { $zip->add($dir); } } $zip->info(array('type' => 'gears', 'gears' => $gears)); $zip->close(); File::download($path, $archive_name, TRUE); } }
public function downloadFile() { $nombre = $_GET['nameFile']; $upload = new File(); return $upload->download($nombre); }
/** * Выгрузка тем */ public function download_action($themes = array()) { if ($themes = $this->input->get('themes', $themes)) { !is_array($themes) && ($themes = explode(',', $themes)); // Если тема одна — называем архив её именем // Если тем несколько — называем архив gears $archive_name = (1 === sizeof($themes) ? end($themes) : 'themes') . '.zip'; $path = TEMP . DS . $archive_name; $zip = new Zip(array('file' => $path, 'create' => TRUE)); foreach ($themes as $theme) { $dir = THEMES . DS . $theme; // Если директория существует и шестерёнка не относится к ядру $zip->add($dir); } $zip->info(array('type' => 'themes', 'themes' => $themes)); $zip->close(); File::download($path, $archive_name, TRUE); } }