I am able to take the backup correctly, but when I am adding the code to save it to different location, the html of the page from which backup is taken is getting inserted in the header.
This is my code:
$cmd=''.$drive .':\wamp\bin\mysql\mysql5.6.12\bin\mysqldump
--user='.$user.' --password='.$pass .' --host=localhost hospitalerp >
'.$outputfilename.'';
exec($cmd, $output, $return);
if ($return != 0) { //0 is ok
die('Error: ' . implode("\r\n", $output));
}else{
echo 'Backup taken successfully';
}
//Download the database file
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.($outputfilename));
//var_dump($myheader);exit;
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($outputfilename));
ob_clean();
flush();
readfile($outputfilename);
//After download remove the file from server
exec('rm ' . $outputfilename);
In the backup file in the header I am getting undesired html text of the webpage like:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-param" content="_csrf">
<meta name="csrf-token" content="MlEzRldGbG53HnwHHg4tKkg2eDYiDl9DQwh.GRUkJwt7GmYRFSIEIg==">
<title></title>
<link href="/hospitalerp/web/assets/69b3a339/css/bootstrap.css" rel="stylesheet">
<link href="/hospitalerp/web/css/site.css" rel="stylesheet">
<link href="/hospitalerp/web/css/custom.css" rel="stylesheet"></head>
<body>
<div class="wrap">
<nav id="w0" class="navbar-inverse navbar-fixed-top navbar" role="navigation">
<div class="container"><div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#w0-collapse"><span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
If I am not using the code for the download part I am getting the backup correctly. Hence there is some problem in the header sent part, which I am not able to find where from this text is coming.
Thanks.
The referred question only addresses the download of backup file at a specified location, but I want the prompt on download as to where the backup file the user wants it to be saved.
how the question heading needs to be updated I am not very sure, but I have updated the same.