最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to Protect a private folder inside uploads folder, if User is not Logged In?

programmeradmin7浏览0评论

I am learning php but i am still quite a noob so please excuse my limitations.

I have a html file that is linked to many PDF files inside a folder called "Clients"

I have placed this folder inside "wp-content/uploads/"

The html page opens as inside the wordpress page.

When a user logs in, it opens the wordpress page that has the html page displaying the links. Clicking on the links opens the PDF file in the same window without going to another page.

This is a multisite wordpress installation and I want to protect the direct URL access to the files inside the "Clients" folder if the user is not logged in.

for example: "https://mywebsite/wp-content/uploads/clients/001.pdf" should not be accessible when the user is not logged in.

I just want to protect direct url access of any files within clients folder.

I have tried using Hakre's solution from

How to Protect Uploads, if User is not Logged In?

and

How to protect uploads in multisite if user is not logged in?

Hakre's solution gives me a prompt to download the files. It also displays blank pages when the user is logged in

I want something as simple as if someone tried to access the PDF files directly via the url it should check if the user is logged in and open the file in the browser (not prompt for download) or else redirect to the home page url.

Could someone please help us out here.

Thanks

I am learning php but i am still quite a noob so please excuse my limitations.

I have a html file that is linked to many PDF files inside a folder called "Clients"

I have placed this folder inside "wp-content/uploads/"

The html page opens as inside the wordpress page.

When a user logs in, it opens the wordpress page that has the html page displaying the links. Clicking on the links opens the PDF file in the same window without going to another page.

This is a multisite wordpress installation and I want to protect the direct URL access to the files inside the "Clients" folder if the user is not logged in.

for example: "https://mywebsite/wp-content/uploads/clients/001.pdf" should not be accessible when the user is not logged in.

I just want to protect direct url access of any files within clients folder.

I have tried using Hakre's solution from

How to Protect Uploads, if User is not Logged In?

and

How to protect uploads in multisite if user is not logged in?

Hakre's solution gives me a prompt to download the files. It also displays blank pages when the user is logged in

I want something as simple as if someone tried to access the PDF files directly via the url it should check if the user is logged in and open the file in the browser (not prompt for download) or else redirect to the home page url.

Could someone please help us out here.

Thanks

Share Improve this question asked Jul 11, 2019 at 0:22 Driv3r333Driv3r333 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default -1

There is a new free plugin available on WordPress. This plugin Protect WordPress Uploads.

https://wordpress.org/plugins/protect-wp-files/

发布评论

评论列表(0)

  1. 暂无评论