• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick PHP CI question.

I have written the following segment of code in order to protect my images from being accessed directly.


<img src='&lt;?php echo base_url(); ?&gt;index.php/Controller/getImage/obama.jpg' width="100px">


//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");
        $img_handle = imagecreatefromjpeg($filepath) or die("");


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.

Solved it, had to remove:


I have no idea why it is screwing up with that, image should exist. Any ideas why?

[eluser]TWP Marketing[/eluser]
Just a guess, you are passing a URL to the file_exists() function. It needs a file path instead of a URL.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.