Reputation: 69
I am trying to create a simple download link
The file I want to download is a .pdf
that the user can upload, and now I want to make it possible to download. With the pop-up box, you know, or just on the chrome download bar
I've tried what every answer says:
<a href="<?=$GUIDELINES_PDF_DIR . $projectId . '.pdf'?>" download="guidelines.pdf">Download PDF</a>
But that leads to "Failed - no file", even though when I check
if(file_exists($GUIDELINES_PDF_DIR . $projectId . '.pdf'))
it returns true!
Some other notes:
I'm pretty shaky on server things, so maybe the same link doesn't work on PHP and on HTML? In that case, how can I find the file?
This link is within a <form>
, so I don't really want to create another <form>
inside it, or do anything that compromises the info that the user has inputed
Thank so much :)
Upvotes: 1
Views: 818
Reputation: 575
Use a right headers:
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='downloaded.pdf'");
Upvotes: 0
Reputation: 943108
$GUIDELINES_PDF_DIR
is a directory on your server's hard disk.
The resulting path you are creating is relative to the root of your server's hard disk and not to the DocumentRoot of your web server.
You need to account for that difference when generating your URL.
Upvotes: 1