
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 0.79 KB | hits: 13 | expires: Never
image protection in codeigniter
//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)){
echo "we are here";
$img_handle = imagecreatefromjpeg($filepath) or die("");
echo $img_handle;
ImageJpeg($img_handle);
}
}
<img src='<?php echo base_url(); ?>index.php/Controller/getImage/obama.jpg' width="100px">
header("Content-type: image/jpeg");
if(file_exists($filepath)){
echo "we are here";
$img_handle = imagecreatefromjpeg($filepath) or die("");
echo $img_handle;
ImageJpeg($img_handle);
}