Ruub
Ruub

Reputation: 629

PHP Download file with header

I know it's something easy, but I can't seem to find the solution. I want to download a pdf from a folder. The pdf is in a folder named forms. My script is in a different folder.

When I try to download the file with the following code:

header('Content-Disposition: attachment; filename="forms/form1976.pdf"');

The filename becomes: forms-form1976.pdf. That's not right, the filename should be: form1976.pdf. How do I enter the the correct folder first?

Upvotes: 1

Views: 2542

Answers (1)

JTC
JTC

Reputation: 3464

You should do something like this

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename=example.pdf');
readfile("/path/to/yourfile.pdf");

Upvotes: 4

Related Questions