how do I protect the pdf files from the directory?

i have a pdf file in one directory called "pdf_docs" ...how can I protect that public should not access the directly the pdf file from the folder? at the same time i need to read the pdf through php and wants to display the content?

i have already reading the pdf through php and displayed the content.. but public users know the path and types the pdf URL, it opens it in the browser?

how do I protect this?

the hosting directory in linux, shared hosting.
LVL 36
Loganathan NatarajanLAMP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jessegivyDeveloperCommented:
Move the folder outside your web accessible directory.  Typical PHP sites have a myriad of include areas, you should store your docs there.
0
jessegivyDeveloperCommented:
...since you already have the code working to display the pdf's, on the off chance that you don't already have an "includes" directory, just create one and add the include path to your server software config file.
0
Loganathan NatarajanLAMP DeveloperAuthor Commented:
I don't understand both replies?

i have directory called,

"/public/web/"

inside, web , i have all the files including pdf folder..

how to protect the pdf folder that public should not access it..

may be user may open the pdf through the browser and reads the content
0
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

szewkamCommented:
You can add .htaccess file to directory where you holding your pdf files with entry: "Deny from all".
That should restricted any direct access to this directory, all subdirectories, and files within it. And your script should still be working :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Loganathan NatarajanLAMP DeveloperAuthor Commented:
i mean, i am asking "can I protect with permission settings of the folder?" that user cannot access it straight.?

by the way, i need to open the file thorough php on the browser? that is way user identify the path and re-opens
0
Loganathan NatarajanLAMP DeveloperAuthor Commented:
@ szewkam

thank you, .htaccess may help, i need to try,

do you have exact syntax sample .. where i can create and upload it stright...

i hope my php script (reading the pdf will always work)
0
szewkamCommented:
In .htaccess place code from the snippet (it is just one line ;)). When creating the file don't forget about dot at the beginning of name. I just check it on localhost, php function still have access to files in directory, so your script should worked as well :)
Deny from all

Open in new window

0
jessegivyDeveloperCommented:
I still say you should create an includes directory to add to your configuration file.  Are you using apache?
0
Loganathan NatarajanLAMP DeveloperAuthor Commented:
@ szewkam

thanks for the great idea.. i will work out tomorrow and give you points.


0
Loganathan NatarajanLAMP DeveloperAuthor Commented:
@ jessegivy:

i am using shared hosting , apache linux
0
Loganathan NatarajanLAMP DeveloperAuthor Commented:
thank you so much, it helped me to complete perfect..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.