Content-disposition:inline header won't show images inline?

Posted by hamstar on Stack Overflow See other posts from Stack Overflow or by hamstar
Published on 2010-05-14T04:06:40Z Indexed on 2010/05/14 4:14 UTC
Read the original article Hit count: 411

I'm trying to show an image inline on a page. It is being served by a codeigniter controller.

class Asset extends MY_Controller {

    function index( $folder, $file ) {

        $asset = "assets/$folder/$file";

        if ( !file_exists( $asset ) ) {
            show_404();
            return;
        }

        switch ( $folder ) {
        case 'css':
            header('Content-type: text/css');
            break;
        case 'js':
            header('Content-type: text/javascript');
            break;
        case 'images':
            $ext = substr( $file, strrpos($file, '.') );
            switch ( $ext ) {
            case 'jpg':
                $ext = 'jpeg';
                break;
            case 'svg':
                $ext = 'svg+xml';
                break;
            }

            header('Content-Disposition: inline');
            header('Content-type: image/'.$ext);
        }

        readfile( $asset );
    }

}

When I load a image in Chrome of FF its pops up the download window. I know when the browser can't display the content inline it will force a download anyway, but these are PNG and GIF images which display in the browser fine otherwise. In IE it doesn't force a download but it displays the image in ASCII.

If I comment out the entire image case it FF and Chrome both display the ASCII but not the image.

I thought setting the content type would allow FF and Chrome to show the actual image, and also allow the location to be used as an src.

The javascript and css shows fine of course.

Anyone got any ideas how I can make the images show properly?

Thanks :)

© Stack Overflow or respective owner

Related posts about content-disposition

Related posts about images