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
soul814
Forum Newbie
Posts: 16
Joined: Sat Apr 09, 2005 5:15 pm
Contact:

download script?

Post by soul814 »

How do you create a download script that like masks where the file is coming from
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Been asked many times.

Code: Select all

<?php

$path_to_file = '/home/username/private/foo.pdf';

header('Content-type: application/pdf');
header('Content-length: '.filesize($path_to_file));
header('Content-disposition: attachment; filename=foo.pdf');
fread($path_to_file);
exit();

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

psst, readfile() not fread() :P
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

feyd wrote:psst, readfile() not fread() :P
*cough*

/me awards feyd the prize jar of ross' pickled onions for spotting the deliberate mistake :lol:
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

d11wtq wrote:/me awards feyd the prize jar of ross' pickled onions for spotting the deliberate mistake :lol:
You were only testing him, eh? :wink:
soul814
Forum Newbie
Posts: 16
Joined: Sat Apr 09, 2005 5:15 pm
Contact:

Post by soul814 »

well thanks =) lol nice test lol
Post Reply