【问题标题】:PHP captcha not displaying in 000webhostPHP验证码未显示在000webhost中
【发布时间】:2013-03-14 01:57:46
【问题描述】:

我正在尝试在托管在000webhost 的网站上显示我的验证码图片,但它显示错误:

imagettftext() [function.imagettftext]: 找不到/打开字体 /home/a3594760/public_html/captcha1.php 第 20 行

虽然我在同一个文件夹中有文件 MAGENTOB.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);

?>

怎么了?

【问题讨论】:

  • 给出完整路径,是否可行(取决于我认为的 GD 库)。

标签: php


【解决方案1】:

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

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

另一个问题可能是需要完整指定文件路径。所以它是这样的:

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

最终的想法与文件权限有关。网络服务器可以读取文件吗?

【讨论】:

    猜你喜欢
    • 2017-05-28
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    相关资源
    最近更新 更多