有什么办法可以阻止图像显示

发布于 2024-10-05 22:59:31 字数 298 浏览 0 评论 0原文

这是 URL http://www.website.com/uploads/pvtimages/image.png

我不希望图像向任何人显示,甚至不向我显示,但可以下载

。 ..e 下载 即仅从特定页面(download.php)

我希望该文件夹中的所有图像都受到保护。

是否可以??使用 php 或 .htaccess 或两者都使用?

Here's the URL http://www.website.com/uploads/pvtimages/image.png

I don't want the image to be displayed to anybody, not even to me but can be downloaded

i...e <a href="http://www.website.com/uploads/pvtimages/image.png">Download</a> i..e only from a specific page (download.php)

I want all images in that folder to be protected.

Is it possible?? using php or .htaccess or both?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

我也只是我 2024-10-12 22:59:31

是的,将以下标头放入您的 .htaccess 文件中:

<Files image.png>
Header set Content-Disposition attachment
</Files>

当然您也可以通过 PHP 发送此标头,但 htacesss 在这种情况下更有意义。但是,它只会阻止它在浏览器中显示。 知道链接的每个人都可以下载!
除非您向网站添加密码保护之类的内容,否则您无法真正保护图像。

不过,您可以通过引用检查来防止某些热链接 - 但这只是为了阻止愚蠢的网站管理员嵌入您的图像......它不会阻止任何真正想要您的东西的人。但如果这对你来说没问题..看看 允许/拒绝使用 .htaccess 进行图像热链接

Yes, put the following header in your .htaccess file:

<Files image.png>
Header set Content-Disposition attachment
</Files>

Of course you can also send this header via PHP, but htacesss makes much more sense in this case. However, it only prevents it from being displayed in the browser. Everyone can download it knowing the link!
You cannot really protect images unless you add something like password protection to your site.

You can prevent some hotlinking through referer checks though - but that's just to stop dumb webmasters from embedding your images.. it won't stop anyone who really wants your stuff. But if that's fine for you.. have a look at Allow/deny image hotlinking with .htaccess

给我一枪 2024-10-12 22:59:31

我最近似乎经常回答这个问题...看,如果您不想通过 URL 访问某些内容,则不需要使用 .htaccess 或 PHP。只是根本不要将其放在文档根目录中。

请参阅我的回答,其中解释了您应该使用的结构。然后你可以使用PHP来下载它;我的此处的答案解释了如何使用 PHP 下载文件。以这种方式做事更容易维护、更容易实施并且更安全。

请注意,这不仅适用于图像等,还适用于 PHP 库和其他任何内容。一般来说,我在文档根目录中有一个PHP文件(例如index.php),一点CSS,JS和一些图像。其他一切通常应该在其他地方。

I seem to be answering this question a lot lately... Look, if you don't want something accessed by URL, you don't need to use .htaccess, or PHP. Just don't put it inside the document root at all.

See my answer here, which explains the structure you should use. You can then use PHP to download it; my answer here explains how to download a file with PHP. Doing things this way is easier to maintain, easier to implement and more secure.

Note that this doesn't just apply to images, etc, but also to your PHP libraries and whatever else. Generally, I have one PHP file (e.g. index.php) in the document root, a little bit of CSS, JS and a few images. Everything else should generally be somewhere else.

始终不够 2024-10-12 22:59:31

将其添加到您的 .htaccess 中。

RewriteEngine On

RewriteRule ^(?:uploads/pvtimages)\b - [F,L]

或者当然可以将其从文档根目录中取出。

这意味着您需要通过 PHP 提供图像。只需 readfile() 并发送正确的标头。

Add this to your .htaccess.

RewriteEngine On

RewriteRule ^(?:uploads/pvtimages)\b - [F,L]

Or of course get it out of your document root.

This means you will need to serve the image via PHP. Just readfile() and send correct headers.

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