How do you make a "Force Download" i.e. that instead of for instance having a mp3 file open in a new tab, rather it will prompt the download.
Force Download?
Collapse
X
-
Use content disposition for this.
[php]
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downl oaded.pdf"');
// The PDF source is in original.pdf
readfile('origi nal.pdf');
?>
[/php]
Taken from php.net/header
Take a look at this too. -
Thanks!
It works!
One more question:
In the page you linked to in the above post, is says that the file may not contain blank lines before or after code.
My question is:
<?php
// May I place code here? if not, is there anywhere in this PHP tag that I may?
// May I place blank lines anywhere IN the PHP tags?
header('Content-disposition: attachment; filename=movie. mpg');
header('Content-type: video/mpeg');
readfile('movie .mpg');
?>Comment
-
I believe you may place code that does not produce any output before the headers.Originally posted by moishyThanks!
It works!
One more question:
In the page you linked to in the above post, is says that the file may not contain blank lines before or after code.
My question is:
<?php
// May I place code here? if not, is there anywhere in this PHP tag that I may?
// May I place blank lines anywhere IN the PHP tags?
header('Content-disposition: attachment; filename=movie. mpg');
header('Content-type: video/mpeg');
readfile('movie .mpg');
?>
Experiment with it!Comment
Comment