download.php 897 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /*
  3. * Download backup file
  4. */
  5. global $CONFIG;
  6. $filename = get_input('file');
  7. //get path to default backup dir specified in plugin settings
  8. $backup_dir = elgg_get_plugin_setting('backup_dir', 'backup-tool');
  9. $file_path = $backup_dir . $filename;
  10. if (file_exists($file_path)) {
  11. //start downlading file
  12. header('Content-Description: File Transfer');
  13. header('Content-Type: application/octet-stream');
  14. header('Content-Disposition: attachment; filename=' . basename($filename));
  15. header('Content-Transfer-Encoding: binary');
  16. header('Expires: 0');
  17. header('Cache-Control: must-revalidate');
  18. header('Pragma: public');
  19. header('Content-Length: ' . filesize($file_path));
  20. ob_clean();
  21. flush();
  22. readfile($file_path);
  23. exit;
  24. } else {
  25. register_error(elgg_echo("backup-tool:message:notexists",array($filename)));
  26. forward("admin/backup/list");
  27. }