Farouk Tawtaw
Farouk Tawtaw

Reputation: 68

No image displayed with Header('Content-type: image/png')

I am having hard time displaying an image pulled out of a database using header('content-type:image/png'), it's returning an empty image and when I check the inspect element the img src name display the name of the php script, can anyone help please?

Here is part of the viewimage.php script attached with the img src

    $data = "SELECT fimgupload1_1 FROM controlpanel1";
    $result2 = mysqli_query($connection,$data);

    while ($row = mysqli_fetch_array($result2))
    {
    $imgData = $row['fimgupload1_1'];
    }
    header('Content-Type: image/png');
    echo $imgData;
    ?>

Upvotes: 0

Views: 992

Answers (1)

Shushant
Shushant

Reputation: 1635

Use readfile or file_get_contents if $row['fimgupload1_1'] is path to your file

$data = "SELECT fimgupload1_1 FROM controlpanel1";
$result2 = mysqli_query($connection,$data);

while ($row = mysqli_fetch_array($result2))
{
$imgData = $row['fimgupload1_1'];
}
header('Content-Type: image/png');
echo readfile($imgData);

Upvotes: 0

Related Questions