PHP - 使文件可供脚本访问,但不可供用户访问

发布于 2024-10-03 06:40:12 字数 91 浏览 0 评论 0原文

我希望用户能够上传文件,但我不希望他们能够查看文件上传到的文件夹的内容。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

他不在意 2024-10-10 06:40:12

上传到不在 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.

躲猫猫 2024-10-10 06:40:12

有多种方法可以实现这一点。

选项 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

Options -Indexes

You might also wanna look at the permissions for the files using chmod.

浅语花开 2024-10-10 06:40:12

并不完全安全,但一个简单的解决方案是将 index.php 文件放置在您不想访问的文件夹中,该文件会将用户重定向回主页。这主要会阻止轻松浏览未索引的文件夹。

<?php
    header('Location: ../../index.html');
?>

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.

<?php
    header('Location: ../../index.html');
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文