Force download script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shubham_amola
Forum Newbie
Posts: 5
Joined: Thu Oct 16, 2008 8:09 am

Force download script

Post by shubham_amola »

i want to force a file to download instead of opening it in browser or acrobat...ny advice????
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Force download script

Post by requinix »

If $filename is the path to the file you want downloaded:

Code: Select all

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . basename($filename));
readfile($filename);
exit;
Post Reply