0

我正在尝试通过 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);
?>

任何帮助将不胜感激,谢谢。

4

1 回答 1

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);
?>
于 2013-10-04T12:44:21.067 回答