The purpose is to download the dumped backup.sql
file after running the sql dumping script (from PHP). Normally, the dumped .sql
file is outputted (written) on the server. Then when i make a href link to that file like <a href="backup.sql">Download File</a>
, the file is opening inside the browser on clicking, instead of being downloading.
How it could be done?
Or you could just use the new HTML5 property download
in the anchor tag of your html.
The code will look something like
<a download href="path/to/the/download/file"> Clicking on this link will force download the file</a>
It works on firefox and chrome latest version. Should I mention that I didn't check it in IE? :P
Add the following lines to your .htaccess
file.
<Files "backup.sql">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</Files>
Another option is serving it with in a .php file eg download.php
have this in download.php
$path = "backup.sql"
header("Content-Type: application/octet-stream"); //
header("Content-Length: " . filesize($path));
header('Content-Disposition: attachment; filename='.$path);
readfile($path);
then
<a href="download.php">Download File</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With