CodeIgniter Forums

Full Version: Hide actual path of an image.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Arun Joshi[/eluser]
I have an album/photos section in my CI site. So I want to hide the real image path from the users. How to implement this in CI?

This was my try. I have a function 'photo' in managephotos controller. When I call this, it prints the url , but not the image
Code:
function photo()
    {
         $thumb = 'albums/5/3/Tulips2.jpg';
         header('Content-type: image/jpeg');
         echo file_get_contents($thumb);
    }

When I called this function it shows "http://localhost/tbf/managephotos/photo" in the page.

Thanks
Arun

El Forum

[eluser]n0xie[/eluser]
Code:
$img = fopen('albums/5/3/Tulips2.jpg', 'r');
        if ($img)
        {
            header('Content-Type: image/jpeg');
            fpassthru($img);
        }

El Forum

[eluser]Agustín Villalba[/eluser]
Another solution could be:
Code:
$filename = 'albums/5/3/Tulips2.jpg';

if (file_exists($filename)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($filename));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filename));
    ob_clean();
    flush();
    readfile($filename);
    exit;
}

I hope it helps...