@SyCoJan 06.2009 — #You can use a hidden iframe so the user clicks the link, which is targeted to the iframe with perhaps an id to identify the file. The iframe runs the above code and the prompt appears. It's a bit neater then a new window.
@walker6o9authorJan 06.2009 — #I'm having the following problem with that code:
Warning: Cannot modify header information - headers already sent by (output started at C:wampwwwannualReportindex.php:72) in C:wampwwwannualReportindex.php on line 278
Warning: Cannot modify header information - headers already sent by (output started at C:wampwwwannualReportindex.php:72) in C:wampwwwannualReportindex.php on line 279
Warning: Cannot modify header information - headers already sent by (output started at C:wampwwwannualReportindex.php:72) in C:wampwwwannualReportindex.php on line 280
@NogDogJan 07.2009 — #Note that, iframe or not, the link needs to point to a server-side script whose only responsibility is to supply the download (as per the code in my first reply); you cannot simply put the download code in the middle of a script that is doing other outputs (such as the HTML page display).
main_page.php: [code=php] <?php /* this is the main page */ ?> <p>blah blah blah <a href="download_file.php">Download file</a> blah blah blah</p> [/code] download_file.php: [code=php] <?php /* This file only does the download, nothing else. */ $file = '/file/you/want/downloaded'; header('Content-Length: '.filesize($file)); header('Content-Type: application/octet-stream'); // change this if you know exact mimie type header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); readfile($file); exit; [/code]