$backup = "Your file data";
$folder = 'assets/db/';
if (!is_dir($folder))
mkdir($folder, 0755, true);
$date = date('m-d-Y-H-i-s', time());
$file_name = "filename-" . $date . '.sql';
$file_url = $folder . $file_name;
$handle = fopen($file_url, 'w+');
fwrite($handle, $backup);
fclose($handle);
header('Content-Type: application/octet-stream');
header("Content-Transfer- Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . $file_name . "\"");
readfile($file_url);
No comments:
Post a Comment