-1

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?

deft321
  • 7
  • 2

2 Answers2

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