PHP文件处理无法显示图像文件

I am trying to display an image file in <img> tag using PHP file handling functions but I'm getting following error instead of an actual image:

image cannot be displayed because it contains errors

Here's my code to read and display the image file:

<?php
header("content-type: image/jpeg");
$filename = "images/sunset.jpg";
$handle = fopen($filename, "rb");
$img= fread($handle, filesize($filename));
fclose($handle);
?>

<img src="<?php echo $img; ?>" alt="image" />

Where I am doing wrong?

You are simply sending the wrong stuff. You declare a content type of image\jpeg, then proceed to return HTML markup.

Get rid of the HTML and just echo $img;