<?php
require '../Common/openDB.php';

// Read file name to be saved (downloaded) to client side
$myfile = fopen("../CurrentlyOpenedDBName.tmp", "r") or die("Unable to open file!");

// Make file name to be downloaded
$file = fgets($myfile)  . ".sql";
fclose($myfile);

// For linux server the file is copied to the Uploads folder by importexport.bash
if($oper_sys == "linux")$file = "../Uploads/{$file}";

if (file_exists($file)) {
	header('Content-Description: File Transfer');
	header('Content-Type: application/octet-stream');
	header('Content-Disposition: attachment; filename='.basename($file));
	header('Content-Transfer-Encoding: binary');
	header('Expires: 0');
	header('Cache-Control: must-revalidate');
	header('Pragma: public');
	header('Content-Length: ' . filesize($file));
	ob_clean();
	flush();
	readfile($file);
	unlink($file);	//remove file from server
	exit;
}
?>
