PHP测试脚本有效,其他脚本中的相同代码无效

时间:2019-07-17 18:20:02

标签: php

我目前正在尝试设置一个动态横幅,通过显示在线客户,时间和日期等来使我们的teampeak服务器变得更加精美。我写了一个小脚本来完成关键的连接工作,但是一旦我尝试显示图像,它将无法正常工作。

因此,我决定测试似乎无法在其他脚本中运行的代码,使其与我想要的方式紧密协作,但仍然无法使用具有增强代码的原始脚本。

这是测试文件:

<?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);
?>

生成以下输出:Test Output

这是我有意从事的主要脚本:

<?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>";
}

?>

这会导致错误,提示诸如“图形由于包含错误而无法显示” Main Output

非常感谢您!

1 个答案:

答案 0 :(得分:0)

我通过查看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;
            }
        }
    }

通过添加“(array)”,您可以强制代码将$ clients变量转换为数组。