我正在尝试通过PHP获取Minecraft播放器的皮肤,这一切都有效,直到用户输入无效的用户名,技术上,如果发生这种情况,脚本应该用替代图像替换未找到的图像,但由于某种原因它没有。 完整的脚本:
<?php
//initial settings
header("Content-type: image/png");
//declere values
$name = $_GET['n'];
//get the image from Minecraft main servers
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/{$name}.png");
//if not found, use an alternative image
if(!$src){
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/char.png");
}
//display the skin
imagepng($src);
?>
任何帮助都会得到满足,谢谢。
答案 0 :(得分:0)
试
<?php
//initial settings
header("Content-type: image/png");
//declere values
$name = $_GET['n'];
//get the image from Minecraft main servers
if(file_exists("http://s3.amazonaws.com/MinecraftSkins/{$name}.png")) {
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/{$name}.png");
//if not found, use an alternative image
else {
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/char.png");
}
//display the skin
imagepng($src);
?>