Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.79 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. image protection in codeigniter
  2. //function to protect images from being accessed directly.
  3. function getImage($img_id){
  4.  
  5.  
  6.       //code to authenticate user goes here then...
  7. $url = $this->data['base_url'].'system/application/images/c/thumbs/';
  8.  
  9. $filepath = $url.$img_id;
  10.  
  11.     header("Content-type: image/jpeg");
  12.   if(file_exists($filepath)){
  13.     echo "we are here";
  14.         $img_handle = imagecreatefromjpeg($filepath) or die("");
  15.     echo $img_handle;
  16.         ImageJpeg($img_handle);
  17.     }
  18.  
  19.  
  20.  
  21.     }
  22.        
  23. <img src='<?php echo base_url(); ?>index.php/Controller/getImage/obama.jpg' width="100px">
  24.        
  25. header("Content-type: image/jpeg");
  26. if(file_exists($filepath)){
  27.     echo "we are here";
  28.     $img_handle = imagecreatefromjpeg($filepath) or die("");
  29.     echo $img_handle;
  30.     ImageJpeg($img_handle);
  31. }