Welcome Guest, Not a member yet? Register   Sign In
Serving an Image with HTTP Headers; white space bug. [SOLVED]
#7

[eluser]Ian Jones[/eluser]
Here's the solution for reference:

Code:
<?php
class Images extends Controller
{
    function Images()
    {
        parent::Controller();
    }
    
    function _remap()
    {
        if($filename = $this->uri->segment(2))
        {
            //$config['uri_protocol' = "REQUEST_URI"; adjusted to remove a php problem where the filename . was being converted to a _
        
            $image = APPPATH . 'users/uploads/' . $filename;
            
            ob_clean();
            header('Content-Type: ' . get_mime_by_extension($image));
            header('Content-Length: ' . filesize($image));
            header('Content-Disposition: inline; filename="'."foo.jpg".'"');
            readfile($image);
        }
    }
}
?>

This works as N0xie suggested, also with fopen() and fpassthru(), although I adapted for the simpler readfile().

You can change 'inline' to 'attachment' to force download, and replace 'foo.jpg' to force a custom filename! (this is great for hiding the real image name, and making the downloadable image semantic / tagged usefully.


Messages In This Thread
Serving an Image with HTTP Headers; white space bug. [SOLVED] - by El Forum - 01-13-2010, 06:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB