PHP - imagepng not working properly
伙计们,首先,我的代码是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <?php ob_start(); $pilot_id = $_GET['id']; //-- Server Variables $dbServer = 'localhost'; $dbUser = 'root'; $dbPassword = '*************'; $dbName = 'bla_tracker'; //-- Server Connection >>> DO NOT CHANGE <<< $sql = mysql_connect("$dbServer","$dbUser","$dbPassword") or die(mysql_error()); $select_db = mysql_select_db("$dbName", $sql); $query = mysql_query("SELECT * FROM acars_users WHERE `id`='".$pilot_id."'") or die (mysql_error()); $row = mysql_fetch_array($query); $nome = $row['nome']; $patente = $row['rank']; $admin = $row['admin']; $checador = $row['checador']; $query_horas = mysql_query("SELECT SUM(flighttime) AS `total` FROM acars_pirep WHERE iduser='".$pilot_id."'") or die (mysql_error()); $row2 = mysql_fetch_assoc($query_horas); $total_min = $row2['total'] + ($row['horas'] * 60); $total = round($total_min/60); if($admin == 1) { $data ="Comandante Master - $nome"; } else { if($checador == 1) { $data ="Comandante Checador - $nome"; } else { if($patente == '4') { $data ="Comandante Sênior - $nome"; } else { if($patente == '3') { $data ="Comandante Instrutor - $nome"; } else { if($patente == '2') { $data ="Comandante - $nome"; } else { if($patente == '1') { $data ="Primeiro Oficial - $nome"; } else { if($patente == '0') { $data ="Copiloto - $nome"; }}}}}}} $rand = rand(1, 8); $my_img = imagecreatefrompng("images/background_$rand.png"); $background = imagecolorallocate($my_img, 0, 0, 255); $text_colour = imagecolorallocate($my_img, 255, 255, 255); imagettftext($my_img, 11, 0, 4, 12, $text_colour,"calibril.ttf","$data"); imagettftext($my_img, 11, 0, 340, 12, $text_colour,"calibril.ttf","$total hrs"); imagettftext($my_img, 11, 0, 4, 98, $text_colour,"calibril.ttf","Brasil Linhas Aéreas"); imagettftext($my_img, 11, 0, 323, 98, $text_colour,"calibril.ttf","voebla.com"); imagesetthickness ($my_img, 5 ); header("Content-type: image/png"); imagepng($my_img); imagecolordeallocate( $text_color ); imagecolordeallocate( $background ); imagedestroy($my_img); ?> |
我们更改了服务器,现在,我得到了:
发生什么事了?
编辑
如果将php错误设置为on,则会收到以下警告:
1 | Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\voebla.com\httpdocs\BLAtracker\sessoes\pilotos\modules\dados\assinatura\assinatura.php:1) in C:\Inetpub\vhosts\voebla.com\httpdocs\BLAtracker\sessoes\pilotos\modules\dados\assinatura\assinatura.php on line 68 |
在第68行,我们有:
1 |
编辑2
深入研究assinatura.php,我已经在php标记之前找到了一个bom,但是现在如何删除它?
找到它了!!!!
好!在php标记之前有一个bom。如何去除它,非常简单。我使用的是Adobe Dreamweaver,下面是步骤:
1-按ctrl+j(页面属性);
2-转到"标题/编码"选项卡,取消选中"包括Unicode签名"复选框;
保存文档,魔法就发生了。不知道为什么我在另一台服务器上没有收到这个错误!
如果不使用Adobe Dreamweaver,记事本++可以转换为不带BOM(字节顺序掩码)的UTF-8:
加上
输出正确,但未被识别为PNG。问题是标题设置不正确,这就是无法识别标题的原因。可能是因为已经设置了头。
取下
否则,请检查是否存在任何会在其上放置另一个头的内容,例如.htaccess添加的头php文件。
编辑:PHP错误确认了这一点。已在设置文件头。很可能是.htaccess向这个目录中的每个php文件添加了一个头文件。这是你的问题,因为我在这个脚本上没有看到任何其他的标题或回音。