我的服务器上有用户在组内上传的图片。 我想通过键入图像的绝对URL来公开限制对这些图像的访问。只有在用户登录系统时才能授予对这些图像的访问权限。
我使用CodeIgniter作为框架,并希望限制在控制器而不是视图上。 现在我无法在视图上获取这些图像。
这是我的结构:
application
- <images_folder>
system
答案 0 :(得分:6)
application
assets
assets > images_folder
system
在此文件夹中创建.htaccess文件并输入Deny from all
创建一个控制器来访问这些图像
<?php
class Preview extends CI_Controller {
function show_image($image_filename) {
$img_path = <path_to_your_img_folder> . $image_filename;
$fp = fopen($img_path,'rb');
header('Content-Type: image/png');
header('Content-length: ' . filesize($img_path));
fpassthru($fp);
}
}
<img src="<?=base_url(preview/show_image/img.png)?>" />
希望这有帮助