For an newsletter script I like to use an image to check if it is read or not. So we made an image like this in our script:
<img src="[url]/getEmailImage/test/">
When this url is triggered it registers that the mail is opened.
At the server side we use this meganism:
// register that the email is read
$this->modelOpslag->changeByToken($token,array('gelezen' => '1'));
// download image and show is
$image = base_url().'external/afbeeldingen/pixel.jpg';
$info = getimagesize($image);
header('Content-Type: '.$info['mime']);
echo file_get_contents($image);
exit;
When i remove the PHP header function is shows something like this:
����JFIF``��rExifMM*JR(1Z``paint.net 4.0.5��
etc...
With the header my browser gives the error: the image cannot be displayed, because is contains errors.
What did I do wrong?
-- EDIT --
I've got no solutions for this specific problem, but i found an alternative in case someone like to use this meganism for their newsletter witch works:
$file = './external/afbeeldingen/pixel.jpg';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
If i understood your question correctly.. you are trying to echo the image, using echo we cannot display the image.. Why don't you use...
<img src="<?php echo file_get_contents($image); ?>" />
you need different headers for image download and for showing image dynamically. Also file encoding format of the php script can cause broken image data.