2017-03-19 154 views
1

我刚将一个站点移动到运行PHP 7的新服务器上。我相信它最初是在PHP 5.4上。下面的网址应该与它的代码显示图像,就像一个验证码:PHP动态图像显示不正确

http://appreviewhelper.com/static/captcha/GkK9yEiaw6

当该URL被击中,下面的代码为然:

$code=rand(1000,9999); 
$code = (string)$code; 
$_SESSION["code"]=$code; 

$im = imagecreate(50, 24); 
$bg = imagecolorallocate($im, 238, 238, 238); //background color blue 
$fg = imagecolorallocate($im, 85, 85, 85);//text color white 
imagefill($im, 0, 0, $bg); 
imagestring($im, 5, 5, 5, $code, $fg); 

header("Cache-Control: no-cache, must-revalidate"); 
header('Content-type: image/png'); 
header("Content-Disposition: inline; filename=captcha.png"); 
imagepng($im); 

imagedestroy($im); 

exit(); 

这是工作罚款旧的服务器。我已经确定安装了PHP GD库并且已经启用了该模块,并且我已经验证了一遍又一遍......但是,我仍然只是得到一个小的空白图像。有任何想法吗?

感谢

编辑:下面是gd_info输出()从该网站:

array(12) { 
    ["GD Version"]=> 
    string(5) "2.1.1" 
    ["FreeType Support"]=> 
    bool(true) 
    ["FreeType Linkage"]=> 
    string(13) "with freetype" 
    ["GIF Read Support"]=> 
    bool(true) 
    ["GIF Create Support"]=> 
    bool(true) 
    ["JPEG Support"]=> 
    bool(true) 
    ["PNG Support"]=> 
    bool(true) 
    ["WBMP Support"]=> 
    bool(true) 
    ["XPM Support"]=> 
    bool(true) 
    ["XBM Support"]=> 
    bool(true) 
    ["WebP Support"]=> 
    bool(true) 
    ["JIS-mapped Japanese Font Support"]=> 
    bool(false) 
} 
+0

似乎为我工作,我正在运行php 7.1.1。我用里面的代码得到一个小图片。错误日志说什么? – xlordt

+0

它似乎也适用于我,并运行7.1。 例如:[链接](http://i66.tinypic.com/1984i_th.png) –

+0

它也适用于php 5.4 .. –

回答

0

我回答自己,因为,几个小时后,我发现这个问题。客户端使用Dropbox与我分享这些文件。显然,Dropbox将文件转换为Unicode。因此,具有图像生成代码的文件在图像输出前发送BOM,导致图像看起来损坏。更改文件的编码为UTF-8修复了问题...

感谢那些查看和回复的人。