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

I am trying to display an image on a page. It is 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 upload an image to Chrome FF, it displays a download window. I know when the browser cannot display the contents in a line, it will still force download, but these are PNG and GIF images that would otherwise be displayed in the browser. In IE, this does not force download, but displays the image in ASCII.

If I comment on the entire image of the image, then FF and Chrome display ASCII, but not the image.

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

javascript and css show of course of course.

- , ?

+5
1

Content-disposition. .

, - . Opera IE, . :

<?php
header('Content-Disposition: inline');
header('Content-type: image/png');

readfile('Untitled.png');

dev , .

, :

<?php
echo substr( "file.ext", strrpos("file.ext", '.') );

".ext" "ext". strrpos() + 1.

+5

All Articles