创建私人图像文件夹? [英] Creating a private image folder?

查看:120
本文介绍了创建私人图像文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不断发展的网站,其中包含约4万张大小的3万张图片,总计12万张.我当前的解决方案是将它们存储在数据库中,从我在栈oveflow上阅读的内容来看,这似乎是一个非常糟糕的主意.

I have a growing website with around 30k images in 4 sizes for a total of 120k. My current solution is storing them in a DB and from what I've read on stack oveflow this seems to be a very bad idea.

我开始明白为什么.我注意到性能急剧下降.认为显而易见的解决方案是将这些图像移动到文件夹设置中,我想使用用户ID作为目录名,然后有一个公共和私有子目录.

I'm starting to see why. I've noticed a drastic decrease in performance. think the obvious solution is to move these images to a folder setup and I'd like to use the users ID as a dir name and then have a public and private sub dir.

结构如下:

/54869
    /public
        /size_1/img1.jpg
        /size_2/img1.jpg
        /size_3/img1.jpg
        /size_4/img1.jpg
    /private
        /size_1/img2.jpg
        /size_2/img2.jpg
        /size_3/img2.jpg
        /size_4/img2.jpg

保护此私有文件夹并仅在文件所有者授予权限的情况下才提供其他用户访问权限的最佳方法是什么?

What is the best way to secure this private folder and only provide other users access if the owner of the file has granted permission?

我也想阻止用户简单地查看任何文件夹的内容,但是我想我可以执行check客户端来解决此问题.

I'd also like to prevent users from simply viewing the contents of any folder but I suppose I could perform a check client side to fix this.

有什么想法或建议吗?

推荐答案

您可以使该文件夹无法通过网络访问(例如,将该文件夹放置在htdocs之外或添加.htaccess规则).

You could make that folder not accessible from the web (e.g. place the folder outside htdocs or add .htaccess rules).

创建一个PHP脚本来处理对私有映像的所有请求. 该脚本必须执行以下操作:

Create a PHP script which handles all requests to the private images. This script would have to do the following:

  • 检查用户是否通过身份验证
  • 检查用户是否有权查看所请求的图像
  • 打开图像并将其打印到浏览器中(您需要设置正确的http标头以确保将内容视为图像)

然后,在您的HTML中,直接指向/secret_image.php?id=3,或者您可能想使用图像的路径/secret_image.php?p=/54869/public/size_1/img1.jpg

Then, in your HTML, simply point to /secret_image.php?id=3 or maybe you want to use the path of the image /secret_image.php?p=/54869/public/size_1/img1.jpg

这篇关于创建私人图像文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆