doujiao3998 2012-06-23 16:29
浏览 22
已采纳

创建私有图像文件夹?

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.

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.

The structure would look like this:

/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?

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.

Any thoughts or suggestions?

  • 写回答

2条回答 默认 最新

  • donglu6303 2012-06-23 16:37
    关注

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

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

    • check if the user is authenticated
    • check if the user is authorized to view the requested image
    • open the image and print it to the browser (you need to set correct http headers to make sure the content is treated as an image)

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。