如何保护所有目录内容,但获得的PHP脚本脚本、目录、内容、PHP

2023-09-02 10:03:49 作者:∮默默哋想沵

我在我的Apache的公共文件夹中的文件夹和它的内容必须在所有时间得到保护。比方说,该文件夹被称为保护。当有人再尝试打开 http://domain.com/protected/random.file ,即有人不应该是能够打开/下载。访问应完全阻塞,没有可能的解决方法。

I have an folder in my apache public folder and it's contents must be protected at all time. Let's say the folder is called 'protected'. When someone then tries to open http://domain.com/protected/random.file, that someone shouldn't be able to open/download it. Access should be completely blocked, with no possible workarounds.

我建立一个门户的公司至极希望能够只文件发布到用户的认可。我所做的门户网站有一个定制PHP的身份验证方法。当登录的用户,并拥有正确的权限(仍然是PHP),即应允许用户下载它被授予访问特定文件(在数据库中定义)。

I'm building an portal for an company wich wants to be able to only publish files to authorised users. The portal I made has an custom made php authentication method. When a user is logged in and has the right permissions (still php), that user should be allowed to download that specific file it's been granted access to (defined in database).

我在想一个脚本在的download.php,被请求的文件时,php收到了文件内容并强制下载。是否有可能阻止所有访问/保护'用的.htaccess,但仍然允许PHP来获取该文件的内容?

I was thinking of an script at download.php, when an file is requested, php gets the file contents and forces an download. Is it possible to block all access to '/protected' with .htaccess, but still allow php to get the file contents?

在此先感谢。

PS。被保护的文件夹,必须在文件夹的public_html

PS. The protected folder hás to be in the public_html folder.

推荐答案

是的。使用

Deny from all

在.htaccess

in .htaccess

和用于下载脚本使用 HTTP下载类

and for the download script use HTTP Download Class

它也有一个速度和恢复的支持。

It also has a speed and resume support.