PHP - 使文件可供脚本访问,但不可供用户访问
我希望用户能够上传文件,但我不希望他们能够查看文件上传到的文件夹的内容。 PHP 脚本应该能够浏览和读取隐藏(对于用户)文件夹中的文件。
有什么想法吗?
I want users to be able to upload files, but I don't want them to be able to view the contents of the folder which the files are uploaded to. A PHP script should be able to browse and read the files in the hidden (for the users) folder.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
上传到不在
public_html
中的文件夹 - 然后只能通过 FTP 或服务器本身访问它们,而不能通过 HTTP 访问。Upload to a folder that's not in
public_html
- they can then only be accessed via FTP or the server itself, not by HTTP.有多种方法可以实现这一点。
选项 1 :就像 kolink 所说,将文件放在 webroot (public_html) 之外
选项 2 :使用 .htaccess 来拒绝访问该目录,如果您不希望列出文件,您可以在 .htaccess 中使用以下内容
您可能还想使用 chmod 查看文件的权限。
Theres multiple ways of accomplishing this.
option1 : like kolink says, place the files outside of your webroot (public_html)
option2 : use a .htaccess where you deny access to the dir, if you dont want the files to be listed you can use the following in your .htaccess
You might also wanna look at the permissions for the files using chmod.
并不完全安全,但一个简单的解决方案是将 index.php 文件放置在您不想访问的文件夹中,该文件会将用户重定向回主页。这主要会阻止轻松浏览未索引的文件夹。
Not totally secure, but a simple solution would be to place an index.php file in the folder you don't want accessed, that redirects the user back to the homepage. This will mainly prevent easy browsing of unindexed folders.