【发布时间】:2018-02-08 22:27:34
【问题描述】:
基本上,它的作用是为我的墙上的固定帖子制作一张图片,上面写着“这面墙已被查看(次数)次。”。这曾经在我的 freewha.com 免费网站上为我工作,但现在我已经切换到运行 apache(ubuntu)的 DigitalOcean 的 VPS,它不起作用。它说页面无法处理请求。我能够发现这是 $text 之后的底部错误,但是我找不到发生这种情况的原因。
<?php
if(!defined('MyConst')) {
die('Direct access not permitted');
}
$viewsOld = file_get_contents("path/views.conf");
$views = $viewsOld + 1;
file_put_contents("path/views.conf", $views);
if ($views < 10) {
$width = 305;
}
elseif ($views < 100) {
$width = 314;
}
elseif ($views < 1000) {
$width = 323;
}
elseif ($views < 10000) {
$width = 332;
}
elseif ($views < 100000) {
$width = 341;
}
elseif ($views < 1000000) {
$width = 350;
}
elseif ($views < 10000000) {
$width = 359;
}
elseif ($views < 100000000) {
$width = 368;
}
elseif ($views < 1000000000) {
$width = 377;
}
else {
}
$text = "This wall has been viewed $views times.";
$my_img = imagecreate( $width, 18 ); //width & height
$background = imagecolorallocate( $my_img, 20, 20, 20 );
$text_colour = imagecolorallocate( $my_img, 0, 255, 0 );
imagestring( $my_img, 10, 0, 0, $text, $text_colour );
imagesetthickness ( $my_img, 5 );
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>
我已经安装了 php 和 php-common,但是它仍然这样做。关于为什么会发生这种情况的任何解释?
【问题讨论】:
-
我认为开关块是专门为这样的时间制作的...php.net/manual/en/control-structures.switch.php
-
如何在我的脚本中实现它?
-
它们有助于对抗多个 elseif 块,
-
@Ice76 它们也不适用于不平等。