Page 1 of 1

Forcing file download for multiple files

Posted: Wed Apr 22, 2009 4:51 am
by TheOracle
The title may be a little misleading, but basically I have a .php page which returns a list of files available for download.

What I want is that when the user clicks on the link to the file, they are prompted to download (regardless of file type)...

I know I need to use headers and content-disposition, but how do I include this on a page where the user may download any 1 of 50 files??

Does anyone have an example of a page they have similar to this (it must be quite common)...

Thanks in advance

Re: Forcing file download for multiple files

Posted: Wed Apr 22, 2009 7:25 am
by miro_igov
Your link href must be download.php?file=filename.pdf

And in download.php set the headers and read the file with readfile()

Do not forget the security, someone could access the other files in your server by passing ?file=../../config.php for example, so you should check the value before to read and output the file.

Re: Forcing file download for multiple files

Posted: Wed Apr 22, 2009 8:15 am
by TheOracle
Could you give an example of what the download.php would look like?

And it's been a while since I retrieved variables from the URl.. Do I use $_GET still?

Thanks,
Paul