Welcome Guest, Not a member yet? Register   Sign In
Hide actual path of an image.
#1

[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
#2

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

[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...




Theme © iAndrew 2016 - Forum software by © MyBB