http://localhost/image.php?application=first
当我从一切正常的代码中触发以下代码时,我不知道我在哪里出错了。
session_start();
$name = $_GET['application'];
$text = rand(10000,99999);
$_SESSION['application'][$name] = $text;
$height = 25;
$width = 65;
$image_p = imagecreate($width, $height);
$black = imagecolorallocate($image_p, 0, 0, 0);
$white = imagecolorallocate($image_p, 255, 255, 255);
$font_size = 14;
imagestring($image_p, $font_size, 5, 5, $text, $white);
imagejpeg($image_p, null, 80);
但是当我为此更改代码时
if (isset($_GET['application']) && !empty($_GET['application'])) {
if (isset($_GET['image']) && $_GET['image'] == 'get'){
session_start();
$name = $_GET['application'];
$text = rand(10000,99999);
$_SESSION['application'][$name] = $text;
$height = 25;
$width = 65;
$image_p = imagecreate($width, $height);
$black = imagecolorallocate($image_p, 0, 0, 0);
$white = imagecolorallocate($image_p, 255, 255, 255);
$font_size = 14;
imagestring($image_p, $font_size, 5, 5, $text, $white);
imagejpeg($image_p, null, 80);
}
}
然后我在浏览器中得到 RAW 格式,所以我添加
header('Content-type: image/jpeg');
imagejpeg($image_p, null, 80);
到代码,现在我收到消息,我的图片被中断,但是当我将它保存在驱动器上并从 IrfanView 启动时,它会正常打开。
我想补充一点,我正在测试ob_start()
功能,但它没有改变任何东西。