在开发过程中我遇到了一个问题。在调用imagedestroy之后,我的脚本将不会执行某些PHP或HTML。
当我删除标题时,它会在imagedestroy之后执行PHP / HTML,但我需要在我的脚本中使用该标题。所以我的问题是; PHP头如何影响PHP脚本。
<?php
header('Content-Type: image/png;');
$im = @imagecreatefrompng('ticket.png') or die("Cannot select the correct image. Please contact the webmaster.");
$text_color = imagecolorallocate($im, 0,0,0);
/*
$name = $_GET['name'];
$from = $_GET['from'];
$to = $_GET['to'];
$time = $_GET['time'];
$date = $_GET['date'];
$agent = $_GET['agent'];
$sno = $_GET['sno'];
$flightno = $_GET['flightno'];
$boardingtime = $_GET['boardingtime'];
$gate = $_GET['gate'];
$seat = $_GET['seat'];
*/
$name = $_POST['name'];
$from = $_POST['from'];
$to = $_POST['to'];
$time = $_POST['time'];
$date = $_POST['date'];
$agent = $_POST['agent'];
$sno = rand(101, 199);
$flightno = $_POST['flightno'];
$boardingtime = $_POST['boardingtime'];
$gate = $_POST['gate'];
$seat = $_POST['seat'];
$text_name = "$name";
$text_from = "$from";
$text_to = "$to";
$text_time = "$time";
$text_date = "$date";
$text_agent = "$agent";
$text_sno = "$sno";
$text_flightno = "$flightno";
$text_boardingtime = "$boardingtime";
$text_gate = "$gate";
$text_seat = "$seat";
$font = 'font.ttf';
#Basis in het midden.
imagettftext($im, 12, 0, 119, 168, $text_color, $font, $text_name);
imagettftext($im, 12, 0, 119, 184, $text_color, $font, $text_from);
imagettftext($im, 12, 0, 100, 201, $text_color, $font, $text_to);
imagettftext($im, 12, 0, 185, 235, $text_color, $font, $text_time);
imagettftext($im, 12, 0, 498, 167, $text_color, $font, $text_date);
imagettftext($im, 12, 0, 509, 184, $text_color, $font, $text_agent);
imagettftext($im, 21, 0, 544, 260, $text_color, $font, $text_sno);
#Top
imagettftext($im, 14, 0, 97, 85, $text_color, $font, $text_flightno);
imagettftext($im, 14, 0, 289, 85, $text_color, $font, $text_boardingtime);
imagettftext($im, 14, 0, 398, 85, $text_color, $font, $text_gate);
imagettftext($im, 14, 0, 486, 85, $text_color, $font, $text_seat);
$rand = rand(0, 3498);
imagepng($im);
imagepng($im, 'images/' . $rand . '.png');
imagedestroy($im);
echo 'This does not display';
?>
答案 0 :(得分:0)
我有一种感觉,问题是浏览器不知道如何处理它接收的数据。根据文档,如果您没有提供imagepng()
的路径,它会将数据输出到浏览器。如果您没有指定正确的标题,则应以文本形式输出。如果有,则应输出为图像。如果您提供的标题告诉浏览器将其视为图像,则图像解析器可能会丢弃附加到图像数据末尾的额外字符“此不显示”。
尝试摆脱imagepng($im)
并注意保存图像然后输出'这不显示'。