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


El Forum

$img = fopen('albums/5/3/Tulips2.jpg', 'r');
        if ($img)
            header('Content-Type: image/jpeg');

El Forum

[eluser]Agustín Villalba[/eluser]
Another solution could be:
$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));

I hope it helps...