PHP验证码在000webhost中不显示


PHP captcha not displaying in 000webhost

我试图在000webhost托管的网站上显示我的captcha图像,但它显示错误:

imagettftext()函数。无法找到/打开的字体/home/a3594760/public_html/captcha1.php第20行

而我有文件magentab . ttf在同一文件夹。我的代码是相同的代码是在我的本地主机工作,但它显示错误时托管在000webhost:

<?php
  include_once('includes/session.php');
  $_SESSION['secure']=rand(1000,9999);
  header('content-type:image/jpeg');
  $text=$_SESSION['secure'];
  $font_size=25;
  $image_width=200;
  $image_height=40;
  $image=imagecreate($image_width,$image_height);
  imagecolorallocate($image,255,255,255);
  $text_color=imagecolorallocate($image,0,0,0);
  for($x=1;$x<=40;$x++)
  {
    $x1=rand(1,120);
    $x2=rand(1,120);
    $y1=rand(1,120);
    $y2=rand(1,120);
    imageline($image,$x1,$y1,$x2,$y2,$text_color);
  }
  imagettftext($image,$font_size,0,15,30,$text_color ,'MAGNETOB.TTF',$text);
  imagejpeg($image);
?>

怎么了?

您的本地主机设置是什么?000webhost的设置是什么?

我的第一个猜测是可能有大小写敏感问题。您的文件名在文件中可能是MAGNETOB.TTF,但在文件系统中可能是magnetob.ttf

另一个问题可能是需要完整指定文件路径。就像这样:

/path/to/my/font/on/web/MAGNETOB.TTF

最终想法与文件权限有关。web服务器能读取文件吗?