1
我一直試圖讓這段代碼工作,但是它沒有顯示任何東西。這將不勝感激,如果你能指出什麼是問題在html無法正常工作的PHP顯示圖像
函數工作後返回橫幅(),但如果我把它帶入HTML它不顯示任何東西,也由於某種原因isup_tf()函數doesnt如果我直接顯示文本,也可以工作。
<?php
function isup_tf(){
$try = @fsockopen("217.182.63.64", "9339", $errno, $errstr, 0.5);
if($try){
return true;
}else{
return false;
}
}
function banner(){
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg('banner.jpg');
$white = imagecolorallocate($jpg_image, 255, 255, 255);
$font_path = 'afb.ttf';
$name = "DarkSoul Server 1 | Unlimited MODS";
$status = (isup_tf() ? "ONLINE" : "OFFLINE");
imagettftext($jpg_image, 21, 0, 12, 48, $white, $font_path, $name);
imagettftext($jpg_image, 40, 0, 12, 121, $white, $font_path, $status);
imagejpeg($jpg_image);
imagedestroy($jpg_image);
}
?>
<html>
<style>
* { text-align: center !important; color: white; font-size: 1em;}
p { color: white; }
</style>
<body style="background: #282828;">
<div>
<h1>Banner</h1>
<?php banner(); ?>
<h1>Status</h1>
<?php return (isup_tf() ? "ONLINE" : "OFFLINE"); ?>
</div>
</body>
</html>
設置PHP顯示錯誤,然後看到什麼樣的錯誤。 –
橫幅會創建一個實際的jpeg圖像,而不是標記,因此您希望將該代碼分離爲可以從圖像標記調用的另一個文件,例如''您應該回顯而不是返回三元函數的結果包裝isup_tf。 – James