[英]PHP Test script works, same code in other script doesn´t
我目前正在嘗試設置一個動態橫幅,通過顯示在線客戶端、時間和日期等來使我們的團隊語言服務器更加花哨。 我寫了一個小腳本來處理關鍵的連接問題,但是一旦我嘗試顯示圖像,它就不起作用了。
因此,我決定測試似乎在不同腳本中不起作用的代碼,使其以我想要的方式緊密工作,但帶有增強代碼的原始腳本仍然不起作用。
這是測試文件:
<?php
header("Content-type:image/png");
$font = "C:\Windows\Fonts\junebug.ttf"; //'junebug.TTF';
$text1 = "It worked";
$image = imagecreatefrompng('banner.png');
$white = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, 12, 0, 100, 100, $white, $font, $text1);
imagepng($image);
imagedestroy($image);
?>
生成以下輸出:測試輸出
這是我有意編寫的主要腳本:
<?php
header('Content-Type: image/png');
include("ts3admin.class.php");
$datum = date("d.m.Y");
$uhrzeit = date("H:i");
$cslots = 0;
$maxslots = 0;
function ts3connect(){
include("connect.php");
$ts3 = new ts3admin( $ts3server, $ts3qport);
$connecting = $ts3->connect();
if($connecting["success"]){
$selected = $ts3->selectServer($ts3port, 'port',true);
if($selected["success"]){
if($ts3user != "" && $ts3pass != ""){
$login = $ts3->login($ts3user, $ts3pass);
return $ts3;
}
return $ts3;
}
} else {
return false;
}
}
if($ts3 = ts3connect()){
$sinfo = $ts3->serverInfo();
if($sinfo["success"]){
$font = "C:\Windows\Fonts\junebug.ttf"; //'junebug.TTF';
$text1 = "It worked";
$image = imagecreatefrompng('banner.png');
$white = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, 12, 0, 100, 100, $white, $font, $text1);
imagepng($image);
imagedestroy($image);
}else{
echo"<pre>Fehler 1: ServerInfo couldn´t be retrieved:<br><hr><br>";
print_r($ts3);
echo"</pre>";
}
}else{
echo"<pre>Fehler 2: Connecting failed:<br><hr><br>";
print_r($ts3);
echo"</pre>";
}
?>
這導致了一個錯誤,說“圖形無法顯示,因為它包含錯誤”主輸出
非常感謝您提前!
我通過查看 apache 文件夾中的 errors.log 文件讓它工作。
@msg 提示(用戶:4782169)
它說 ts3admin.class.php 的第 3245 行有錯誤
private function loadQueryData()
{
$whoAmI = $this->getElement('data', $this->whoAmI());
$this->runtime['bot_name'] = $whoAmI['client_nickname'];
$clients = $this->clientList();
foreach((array)$clients['data'] as $client) //<-- This one
{
if(strstr($this->runtime['bot_name'], $client['client_nickname']))
{
$this->runtime['bot_clid'] = $client['clid'];
break;
}
}
}
通過添加“(數組)”,您可以強制代碼將 $clients 變量轉換為數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.