How to create downloadable link to text file?
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>
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