0

在开发过程中,我遇到了一个问题。调用 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';

?>
4

1 回答 1

0

我有一种感觉,问题在于浏览器不知道如何处理它接收的数据。根据文档,如果您不提供路径,imagepng()则会将数据输出到浏览器。如果您没有指定正确的标题,它应该输出为文本。如果有,它应该输出为图像。如果您提供告诉浏览器将其视为图像的标题,则图像解析器可能会丢弃附加到图像数据末尾的额外字符“这不显示”。

尝试摆脱imagepng($im)并观看它保存图像然后输出“这不显示”。

http://us2.php.net/imagepng

于 2012-06-26T00:27:31.757 回答