image protection in codeigniter

前端 未结 2 828
甜味超标
甜味超标 2020-12-22 14:02

I am using the following code in my controller:

//function to protect images from being accessed directly.
function getImage($img_id){


      //code to auth         


        
相关标签:
2条回答
  • 2020-12-22 14:11

    you sure the image can be accessed via $this->data['base_url'].'system/application/images/c/thumbs/obama.jpg , you tried accessing it on browser, right?

    Also, avoid printing text before rendering the image, it may corrupt the image.

    If still doesn't work, let us know the error page screenshot, whats its saying.

    0 讨论(0)
  • 2020-12-22 14:19

    Your problem is that you are outputing text to the browser, and then the image. The browser will try to render the image but it will be corrupted.

    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);
    }
    

    Also, if you want to do an echo you can't send an header saying "hey, this is a jpeg image".

    0 讨论(0)
提交回复
热议问题