This might seem like a duplicate question but I have tried the solution given in the similar questions.
这似乎是一个重复的问题,但我尝试了类似问题中给出的解决方案。
I want to limit access to files in a few folders on my apache server so that they can only be served through a php script to only the users logged in to the part of my system that should have access to any particular folder.
我想限制访问我的apache服务器上的几个文件夹中的文件,这样它们只能通过php脚本提供给登录到我系统中应该有权访问任何特定文件夹的部分的用户。
Other solutions suggest using the .htaccess
其他解决方案建议使用.htaccess
deny from all
allow from 127.0.0.1
But that seems to deny the files from everywhere.Including the local php scripts.
但这似乎拒绝了无处不在的文件。包括本地的PHP脚本。
Im considering .htpasswd but that is an extra level of user credentials that needs to be handeled and I'd prefere to avoid that.
我正在考虑.htpasswd,但这是一个额外的用户凭证级别需要被处理,我宁愿避免这种情况。
How should I get around this? Is there any better way of storing the files?
我应该怎么解决这个问题?有没有更好的存储文件的方法?
2 个解决方案
#1
0
htaccess cannot deny access to files via php using include/require functions. If your php include is not accessing the file then the problem is the path to the file.
htaccess无法使用include / require函数拒绝通过php访问文件。如果您的php include没有访问该文件,则问题是该文件的路径。
#2
0
Somehow php was restricted by the
不知何故,php被限制了
deny from all
allow from 127.0.0.1
to include and require files in the affected folders. This goes against what I can read from the apache documentation how this should work and I have no real answer why. The problem persisted both on my localhost using Xampp and on the webhotel one.com.
在受影响的文件夹中包含和要求文件。这违反了我从apache文档中可以读到的应该如何工作,我没有真正的答案为什么。问题在我使用Xampp的本地主机和webhotel one.com上都存在。
My original question was badly formed since I used require to test if I had read access to the folder when I actually wanted to use readfile.
我原来的问题很糟糕,因为我使用require来测试当我真正想要使用readfile时是否具有对该文件夹的读取权限。
My main concern was that I wanted to serve files for download from an inaccessible directory. And the
我主要担心的是我想从一个无法访问的目录中提供下载文件。而且
readfile($filename);
could still access the files.
仍然可以访问文件。
The soultion to this problem was that I realized that readfile() and include() somhow gets different permissions. I could not find this in any documentation.
这个问题的灵魂在于我意识到readfile()和include()somhow获得了不同的权限。我在任何文档中都找不到这个。
#1
0
htaccess cannot deny access to files via php using include/require functions. If your php include is not accessing the file then the problem is the path to the file.
htaccess无法使用include / require函数拒绝通过php访问文件。如果您的php include没有访问该文件,则问题是该文件的路径。
#2
0
Somehow php was restricted by the
不知何故,php被限制了
deny from all
allow from 127.0.0.1
to include and require files in the affected folders. This goes against what I can read from the apache documentation how this should work and I have no real answer why. The problem persisted both on my localhost using Xampp and on the webhotel one.com.
在受影响的文件夹中包含和要求文件。这违反了我从apache文档中可以读到的应该如何工作,我没有真正的答案为什么。问题在我使用Xampp的本地主机和webhotel one.com上都存在。
My original question was badly formed since I used require to test if I had read access to the folder when I actually wanted to use readfile.
我原来的问题很糟糕,因为我使用require来测试当我真正想要使用readfile时是否具有对该文件夹的读取权限。
My main concern was that I wanted to serve files for download from an inaccessible directory. And the
我主要担心的是我想从一个无法访问的目录中提供下载文件。而且
readfile($filename);
could still access the files.
仍然可以访问文件。
The soultion to this problem was that I realized that readfile() and include() somhow gets different permissions. I could not find this in any documentation.
这个问题的灵魂在于我意识到readfile()和include()somhow获得了不同的权限。我在任何文档中都找不到这个。