Header("Content-Type: image/jpeg");
<html><body>
JPEG images do not contain html.
HTML is not served under a Content-Type: of image/jpeg.
One of these is wrong; apparently the second, since you're saving the JPEG in a file and then referencing it in the <img> tag. Incidentally, I recommend you give the file a unique name (randomly generated, say) that you store in the session; otherwise if two people visit your site at the same time their random images will collide.