Page 1 of 1

mysql backup through php ask for save as

Posted: Fri Mar 04, 2011 6:13 am
by manojsemwal1
Hi i want to give the rights to user to take the database backup.but its store in the server only .
i want, if user click on backup button its ask for save target and the database as per user define path.

iam using the following code but its not working
$backupFile = $db_name."_".date( "Y-m-d-H-i-s" ).".gz";
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=$backupFile");

Thanks
Manoj

Re: mysql backup through php ask for save as

Posted: Fri Mar 04, 2011 6:34 am
by litebearer
if the file already exists, simply create a link to it. No need for headers

Re: mysql backup through php ask for save as

Posted: Fri Mar 04, 2011 7:17 am
by manojsemwal1
Thanks for ur quick reply.....
iam using the following code to create the file..... but at the same time how can i use save target as .sql format............

$handle = fopen('db-backup-'.date( "Y-m-d-H-i-s" ).'.sql','w+');
fwrite($handle,$return);
fclose($handle);


Thanks

Re: mysql backup through php ask for save as

Posted: Fri Mar 04, 2011 2:44 pm
by litebearer

Re: mysql backup through php ask for save as

Posted: Fri Mar 04, 2011 10:51 pm
by manojsemwal1
thanks once again

I had read that earlier but not got a solution.................

Pl give another one..............

Thanks.

Re: mysql backup through php ask for save as

Posted: Sat Mar 05, 2011 4:42 am
by manojsemwal1
Thanks
I have found the solution ...........its work for me.........

if any body want to do this pl use it..........

insert the correct file name and path.........
$fullPath=$backup_path.$backupFile;


//echo $fullPath;
// File Exists?
if(file_exists($fullPath) )
{
echo $fullPath;
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);


$ctype="application/zip";
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($fullPath)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
ob_clean();
flush();
readfile( $fullPath );

}

Thanks
Manoj Semwal