[eluser]theknight[/eluser]
I have written the following segment of code in order to protect my images from being accessed directly.
View:
Code:
<img src='<?php echo base_url(); ?>index.php/Controller/getImage/obama.jpg' width="100px">
Controller:
Code:
//function to protect images from being accessed directly.
function getImage($img_id){
//code to authenticate user goes here then...
$url = $this->data['base_url'].'system/application/images/c/thumbs/';
$filepath = $url.$img_id;
header("Content-type: image/jpeg");
if(file_exists($filepath)){
$img_handle = imagecreatefromjpeg($filepath) or die("");
ImageJpeg($img_handle);
}
}
Anyway, I am not having any luck. It is returning a broken image, rather then the actual image itself. Why?
All help appreciated. Thank you.