2

We have some PDF files and instead of giving direct link to to file, we want it to render through php so that only authenticated users are able to download the pdf file. Thus we dont need to give filepath to user.

Is it possible?

Mangesh

user1806296
  • 41
  • 2
  • 11

1 Answers1

5

You can, here is a sample:

<?php
$file = './path/to/the.pdf';
$filename = 'You dont know where I am.pdf';

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

@readfile($file);
?>
André Catita
  • 1,313
  • 16
  • 19