0

I want to secure the display of my PDF : firstly hide the PDF's source link for the user, and secondly make PDF download impossible.
I was on the first point, I used :

<?php $file = "./src/file.pdf"; header("Content-type: application/pdf"); header("Content-Length: " . filesize($file)); readfile($file); ?> 

That work very well on a page without any HTML, but if I only add :

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>TEST</title> </head> <body> <div> <!-- Some elements --> </div> <div> <?php $file = "./src/file.pdf"; header("Content-type: application/pdf"); header("Content-Length: " . filesize($file)); readfile($file); ?> </div> </body> </html> 

That dosn't work at all
So how can I do ? Because I want the PDF at this place, surrounded by HTML.

If someone have the solution, or more than that, the solution for hidding PDF's source link and secondly make PDF download impossible.

I thank you very much for your time and your patience !

1

1 Answer 1

0

As Ken Lee pointed out you can't have any output before calling header.

<?php $file = "./src/file.pdf"; header("Content-type: application/pdf"); header("Content-Length: " . filesize($file)); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>TEST</title> </head> <body> <div> <!-- Some elements --> </div> <div> <?php readfile($file); ?> </div> </body> </html> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.