Paul R
Paul R

Reputation: 2797

Restrict direct access to pdf, but allow view through <object>

After googling I didn't find answer to my question. So, question. I have site with http://www.emathhelp.net Inside it there is folder with pdf files.

I want to restrict direct access to pdf files, so http://www.emathhelp.net/1/3192849.pdf will return error, but a page with code <object data="pdf/1/3192849.pdf"></object> will correctly fetch pdf.

One of the attempts was to redirect all urls that end with .pdf to php script which then will find the page where pdf is embedded and redirect there. It was done, however inside <object></object> there is black screen, because I guess data="pdf/1/3192849.pdf" is rewritten also an thus infinite loop is created.

Can you help me? Maybe there are some solutions through .htaccess, maybe I don't need to use <object>. Please, write your suggestions.

Upvotes: 1

Views: 1061

Answers (1)

Ozzy
Ozzy

Reputation: 8322

Take it out of the web root folder. However, when it is supposed to be shown, use PHP to copy it to a temp location in your web root folder and display it to the user who is meant to see it. Keep a record of the temp file in a database, so that it is removed after say 1-2hrs.

Links:

Upvotes: 1

Related Questions