ronka
ronka

Reputation: 452

header('Content-Type: image/jpeg') turns page blank

I'm writing my first PHP code and I'm building a form in which the user uploads an image, the image is save in the directory and the name is saved in the database. Than I have a page that displays that that data from the database i want it to show to image.

$imgdir = 'images/' . $result['fileName'];
$imgsrc = ImageCreateFromJpeg($imgdir);
header('Content-Type: image/jpeg');
imagejpeg($imgsrc);

the output i get is this(notice the block on top left) enter image description here

but if remove header('Content-Type: image/jpeg'); i got this output(whats in blue is the dir to the image i echoed to check if correct, and it is).

enter image description here

thanks!

Upvotes: 1

Views: 1424

Answers (1)

user3700999
user3700999

Reputation:

You'd better use a simple html img tag, i guess, no need to overdo things :-)

<img src="<?php echo 'images/' . $result['fileName'] ?>" alt="" />

Upvotes: 1

Related Questions