2016-12-24 38 views
1

我需要上传很多属于不同客户&的图像也是保密的。 Codeigniter已用于后端。Codeigniter:如何保护公共访问和搜索引擎的图像

的图像具有路径www.example.com/customerID/image.jpg

我已阅读关于保持根级别&以上的图像的方法,然后将它们复制暂时当用户的需求。但它看起来非常复杂,因为如果用户突然关闭浏览器,则需要在每次加载页面时执行其他检查以删除以前未删除的图像。

还有哪些其他有效的选择?

编辑: 我不是在寻找一般性的建议,但实际上如何实现在codeigniter中只使用代码。

+0

参考:http://www.naturefocused.com/articles/image-protection.html –

回答

2

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

创建一个处理私人图像的所有请求的PHP脚本。如果用户被授权

-check如果用户进行身份验证
检查以查看请求的图像打开图像并将其打印到浏览器
(需要设置:此脚本必须做到以下几点正确的HTTP头,以确保内容被视为图像)

演示

getimage.php

if (LoggedInUserCanAccessThisFile())//this is optional user define function as requirement if you want that only login user can see image then with the help of your session variables or cookies you can return this function true or false 
    { 
    $file = 'privatedir/image.jpg'; 
    $type = 'image/jpeg'; 
    header('Content-Type:'.$type); 
    header('Content-Length: ' . filesize($file)); 
    readfile($file); 
    exit(); 
    } 

home.php/otherpage.php

<img src="getimage.php" /> 

(你可以使用SRC = “getimage.php?用户id = 123”,进入getimage.php并检查该用户登录或不显示图像)

(也可以使用SRC = “getimage.php?用户ID = 123 & imgfilename = image3.jpg” 动态图像的代码,并进入getimage.php作为

$file = 'privatedir/'.$_GET["imgfilename"];