Display an image through PHP

From: Date: Tue, 13 May 2003 04:25:24 +0000
Subject: Display an image through PHP
Groups: php.general 
Request: Send a blank email to php-general+get-147393@lists.php.net to get a copy of this message
Hi, I'm trying to display an image dynamically, by extracting it from a database. I've read the user-contributed notes at php.net for the header() command, and also experimented with using the headers returned from a direct look at a real .jpg and came up with this code:
    $picture = mysql_fetch_row($res);
    header('Accept-Range: bytes');
    header('Content-Length: '.strlen($picture[0]));
    header('Content-Type: '.$picture[1]);
    header('Content-Disposition: inline; filename=file.jpg');
    echo $picture[0];
Assume that $picture is an array, [0] is the image data, and [1] is the mime type (in other words, assume valid inputs) Using this code, I get a broken image. Anyone with header experience know how to trick the browser into displaying the stupid picture? Thanks, Greg

« previous php.general (#147393) next »