CodeIgniter Forums
$this->output - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: $this->output (/showthread.php?tid=70111)



$this->output - Marcel - 02-22-2018

hi all

I did this function to prevent direct linking to images on my site.
if user links https://mydomain/avatar/36/WU8VgWCXx4 and isnt logged in he is taken to the login page.

the MYcontroller handles the logged in user part.

my question doing this the image will always be downloaded nothing in the cache as when I link normally https://mydomain/images/avatar-36-WU8VgWCXx4.jpg

is there a way to achieve this ?

Code:
function app_avatar( $imgsize,$imguserid )
   {
       $filename = '../members/avatars/avatar-x'.$imgsize.'-'.$imguserid.'.jpg';
       if ( file_exists( $filename ) ) {
           header( 'Content-Length: ' . filesize( $filename ) );
           $finfo = finfo_open( FILEINFO_MIME_TYPE );
           header( 'Content-Type: ' . $finfo );
           header( 'Content-Disposition: inline; filename="' . $filename . '";' );
           $jpg = file_get_contents( $filename );
           $this->output->set_output( $jpg );
       } else {
           $filename = "assets/img/no-avatar.jpg";
           header( 'Content-Length: ' . filesize( $filename ) );
           $finfo = finfo_open( FILEINFO_MIME_TYPE );
           header( 'Content-Type: ' . $finfo );
           header( 'Content-Disposition: inline; filename="' . $filename . '";' );
           $jpg = file_get_contents( $filename );
           $this->output->set_output( $jpg );
       }
   }

 Thanks


RE: $this->output - InsiteFX - 02-22-2018

A quick search found this article:

Tips and Techniques to Protect Images on the Internet