Reputation: 352
I am using the below code for secure pdf download. everything is working fine. the problem is downloaded pdf file name concats folder name also. I want to suppress the Folder name. Also provide any better solution for secured pdf downloads. Please check the below.
$pdf_file = base64_decode($_GET['file_name']);
$dir="Secured_files";
$file = $dir."/".$pdf_file .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
file name is : here Secured_files
is Folder name and xxxxx
is file name.
Secured_filesxxxxx.pdf
Upvotes: 0
Views: 313
Reputation: 3121
$file_label = $pdf_file .".pdf";
$file = $dir."/".$file_label;
header("Content-Disposition: attachment; filename=" . urlencode($file_label));
Upvotes: 1
Reputation: 3730
Replace
header("Content-Disposition: attachment; filename=" . urlencode($file));
with
header("Content-Disposition: attachment; filename=" . urlencode($pdf_file));
$file
is the full filepath not the name. You only want the name.
If this does still not work do a var_dump($file)
and post the result.
Upvotes: 0