rain13 Posted July 8, 2010 Share Posted July 8, 2010 If i make normal link to text file, browser displays that file in it's window, but how do I make link that always brings up "Save As" dialog?I am adding some links to my scripts, but it's really annoying if you have to click the link, then select all and then copy(or save page as). Making link that brings up save dialog for text file, would save lot's time. Link to comment Share on other sites More sharing options...
jeffman Posted July 8, 2010 Share Posted July 8, 2010 I don't think HTML can do that. A server-side script can do it, if you have access to PHP or ASP.NET or something. Link to comment Share on other sites More sharing options...
End User Posted July 8, 2010 Share Posted July 8, 2010 DD is correct, you'll have to use the Content-type header to force the download of a text file. I found this on the net, but haven't tested it:Content-type: application/octet-streamContent-Disposition: attachment; filename="myfile.txt"I also found this bit (also untested): <?php $string = "bla bla bla"; // this can be a variable string or a row from a sql query or something else... $ext = "txt"; // file extension $mime_type = (PMA_USR_BROWSER_AGENT == 'IE' || PMA_USR_BROWSER_AGENT == 'OPERA') ? 'application/octetstream' : 'application/octet-stream'; header('Content-Type: ' . $mime_type); if (PMA_USR_BROWSER_AGENT == 'IE') { header('Content-Disposition: inline; filename="' . $filename . '.' . $ext . '"'); header("Content-Transfer-Encoding: binary"); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); print $string; } else { header('Content-Disposition: attachment; filename="' . $filename . '.' . $ext . '"'); header("Content-Transfer-Encoding: binary"); header('Expires: 0'); header('Pragma: no-cache'); print $string; }?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.