How do I force-download for multiple links? If user clicks link1 they download pdf1.pdf. If user clicks link2 they download pdf2.pdf. Is there a way to check which link they clicked on?
Asked
Active
Viewed 127 times
-1
-
1`link1` and the same for link2? – georg Jan 26 '15 at 06:56
-
I think you zip file and download. http://stackoverflow.com/questions/1754352/download-multiple-files-as-zip-in-php – Andrew Nguyen Vo Jan 26 '15 at 06:57
-
1lookup on Google. This is basic HTMl, nothing to do with PHP – user3036342 Jan 26 '15 at 06:57
-
possible duplicate of [How do I force-download different .pdfs in same script?](http://stackoverflow.com/questions/28146669/how-do-i-force-download-different-pdfs-in-same-script) – Jan 26 '15 at 08:27
2 Answers
3
Try
<?php
$FileName = 'file.pdf';
header('Content-disposition: attachment; filename="'.$FileName.'"');
readfile($FileName);

Razvan Baba
- 155
- 9
-
If I try doing that and I have $FileName = 'file1.pdf'; $FileName = 'file2.pdf'; It keeps bringing back file1.pdf and not file2.pdf – deft321 Jan 26 '15 at 08:03
0
$file_url = 'your_file.someting';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
readfile($file_url);
P.S. use proper content-type for your file e.g application/zip
for ZIP
files

Murtaza Khursheed Hussain
- 15,176
- 7
- 58
- 83