$zipfile->store('yacs/' . $file, Safe::filemtime($file_path . $file), $content); } // to be included in tar file as well $all_files[] = $file_path . $file; } else { $context['text'] .= BR . 'cannot read ' . $file_path . $file; } // avoid timeouts if (!($index++ % 50)) { Safe::set_time_limit(30); SQL::ping(); } } // save the zipfile if ($handle = Safe::fopen($context['path_to_root'] . $file_name . '.zip', 'wb')) { fwrite($handle, $zipfile->get()); fclose($handle); $context['text'] .= BR . Skin::build_link($file_name . '.zip', $file_name . '.zip', 'basic'); } // start the tar file include_once '../included/tar.php'; $tarfile = new Archive_Tar($context['path_to_root'] . $file_name . '.tgz'); // extend the tar file as well if ($tarfile->createModify($all_files, '', $file_path)) { $context['text'] .= BR . Skin::build_link($file_name . '.tgz', $file_name . '.tgz', 'basic'); } $context['text'] .= "</p>\n"; // display the execution time $time = round(get_micro_time() - $context['start_time'], 2); $context['text'] .= '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>'; // forward to the index page
$items = Files::list_by_date_for_anchor($type . ':' . $id, 0, 20, 'raw'); } // archive each file $file_path = $context['path_to_root'] . Files::get_path($type . ':' . $id); foreach ($items as $id => $attributes) { // read file content if ($content = Safe::file_get_contents($file_path . '/' . $attributes['file_name'], 'rb')) { // add the binary data $zipfile->deflate($attributes['file_name'], Safe::filemtime($file_path . '/' . $attributes['file_name']), $content); } } // // transfer to the user agent // // send the archive content if ($archive = $zipfile->get()) { // suggest a download Safe::header('Content-Type: application/octet-stream'); // suggest a name for the saved file $file_name = utf8::to_ascii($item['title']) . '.zip'; Safe::header('Content-Disposition: attachment; filename="' . str_replace('"', '', $file_name) . '"'); // file size Safe::header('Content-Length: ' . strlen($archive)); // already encoded Safe::header('Content-Transfer-Encoding: binary'); // enable 30-minute caching (30*60 = 1800), even through https, to help IE on download http::expire(1800); // strong validator $etag = '"' . md5($archive) . '"'; // manage web cache if (http::validate(NULL, $etag)) {
// read file content if (($content = Safe::file_get_contents($file_prefix . $file)) !== FALSE) { // store binary data $zipfile->store($file, Safe::filemtime($file_prefix . $file), $content); // avoid timeouts if (!($index++ % 50)) { Safe::set_time_limit(30); SQL::ping(); } } } // suggest a download Safe::header('Content-Type: application/zip'); Safe::header('Content-Disposition: attachment; filename="backup_' . $context['skin'] . '.zip"'); // send the archive content echo $zipfile->get(); // do not allow for regular rendering return; // no file } else { $context['text'] .= BR . i18n::s('No item has been found.') . '</p>' . "\n"; } // select the operation to perform } else { // the splash label $context['text'] .= '<p>' . i18n::s('Please select the action to perform.') . "</p>\n"; // backup $context['text'] .= Skin::build_block(i18n::s('Backup database content'), 'title'); // introductory text $context['text'] .= '<p>' . i18n::s('This script will generate SQL statements necessary to rebuild your database from scratch. Please file it at your computer for backup purpose.') . "</p>\n"; // backup optimization