hi friends, i got a problem for displaying image from the following source code

include "connection.php";
$id=$_GET['d'];// value of 'd' is getting from the another page
//$image_folder=''; //absolute path to image folder
$msql="SELECT * from client_logo where client_id='$id'";
$mresult= mysql_query($msql) or die(mysql_error());
if($row > 0)
while ($row1 = mysql_fetch_array ($mresult))

// get the filename extension
$ext = substr($domain, -3); // here -3 reads 3 characters from last position of the string in reverse order.

// set the MIME type
switch ($ext)
case 'jpg':
$mime = 'image/jpeg';
case 'gif':
$mime = 'image/gif';
case 'png':
$mime = 'image/png';
$mime = false;

// if a valid MIME type exists, display the image
// by sending appropriate headers and streaming the file

if ($mime)
header('Content-type: '.$mime);
header('Content-length: '.filesize($domain));
$file = @fopen($domain, 'rb');

if ($file)


if i give image location with image name directly instead of retrieving the name of image from database, then this code works very well. this does not.
if any of u have a better solution then suggest me.
thx in advance.