Php imagepng与include的组合不再起作用
为什么这个脚本不再有效?该脚本使用了以前的php版本(5.6之前)和数据库连接的默认编码:Php imagepng与include的组合不再起作用,php,mysql,mysqli,include,php-5.6,Php,Mysql,Mysqli,Include,Php 5.6,为什么这个脚本不再有效?该脚本使用了以前的php版本(5.6之前)和数据库连接的默认编码: include('connect-to-database-with-utf8.php'); header('Content-Type: image/png'); $im = imagecreatetruecolor(45, 22); $text_color = imagecolorallocate($im, 255, 0, 0); imagestring($im, 10, 5, 3, '1234
include('connect-to-database-with-utf8.php');
header('Content-Type: image/png');
$im = imagecreatetruecolor(45, 22);
$text_color = imagecolorallocate($im, 255, 0, 0);
imagestring($im, 10, 5, 3, '1234', $text_color);
imagepng($im);
imagedestroy($im);
webbrowser说图像无法显示,因为它包含错误。。。但如果我不通过直接将代码复制到文件中来使用任何include,它就会工作。很奇怪
包含文件“connect-to-database-with-utf8.php”包含:
$mysqli = new mysqli('db_host', 'db_user', 'db_password');
$mysqli->select_db('db_name');
// set charset to utf-8 for database requests
$mysqli->set_charset('utf-8');
$stmt = $mysqli->prepare('SET NAMES \'utf8\'');
$stmt->execute();
$stmt->close();
$stmt = $mysqli->prepare('SET CHARACTER SET \'utf8\'');
$stmt->execute();
$stmt->close();
connect-to-database-with-utf8.php
页面是否在文件末尾的
前面有空格,后面可能有空格?@Rasclatt sry,但这不是问题……启用错误报告(始终在开发和测试代码时)<代码>错误报告(E_全部);ini设置(“显示错误”,1)代码>位于代码顶部,并查看在注释出//imagepng($im)
时得到的结果。很可能有一些错误/注意到输出破坏了图像输出。sry,没有与此问题相关的错误