My php file creates a png image. The image is ready and is saved into the given folder, but cannot load it on the page (it just show the place of the image, but empty).
This is the "captcha_image.php":
<?php
$dirPath="/opt/lampp/htdocs/WebSiteFolder/dfxCaptcha/";
$font='/opt/lampp/htdocs/WebSiteFolder/DejaVuSerif-Bold.ttf';
$imgWidth=200;
$imgHeight=50;
global $image;
$image = imagecreatetruecolor($imgWidth, $imgHeight) or die("Cannot initialize a new GD image stream.");
$background_color = imagecolorallocate($image, 0, 0, 0);
$text_color = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, $imgWidth, $imgHeight, $background_color);
$letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$len = strlen($letters);
$letter = $letters[rand(0, $len - 1)];
$word = "";
for ($i = 0; $i < 4; $i++) {
$letter = $letters[rand(0, $len - 1)];
imagettftext($image, 15, 0, $i*50+25, 50, $text_color, $font, $letter);
$word .= $letter;
}
$_SESSION['captcha_string'] = $word;
$images = glob($dirPath."*.png");
foreach ($images as $image_to_delete) {
@unlink($image_to_delete);
}
header ("Content-type: image/png");
imagepng($image, $dirPath."image" . time() . ".png");
?>
I use this in the HTML:
<img src="includes/captcha_image.php" id="captcha">
How can I display the image to the page?