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

#1
[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='&lt;?php echo base_url(); ?&gt;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.

#2
[eluser]theknight[/eluser]
Solved it, had to remove:

if(file_exists($filepath)){
}

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

#3
[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-2019 MyBB Group.