create_captcha - 函数返回false - Codeigniter

时间:2018-01-20 14:06:26

标签: php codeigniter

这是我的目录结构:

enter image description here

我的代码如下:

$data['msg'] = $msg ;

$this->load->helper('captcha');

$captcha = array(
    'word' => rand(9999,99999),
    'img_path'  => './captcha/',
    'img_url'   => base_url().'/captcha/',
    'font_path' =>  './captcha/font.ttf',
    'img_width' => '130',
    'img_height'=> 50,
    'expiration'=> 5800
);

$cap = create_captcha($captcha);
$data['image'] = $cap['image'] ;
echo var_dump($cap);
return;

但我的输出返回bool(false)

2 个答案:

答案 0 :(得分:0)

这里有两种可能性。要么您没有安装GD扩展程序(如果您在启用apt的Linux环境中,请尝试apt-get install php-gdapt-get install php7.0-gd(取决于您的PHP版本)或询问您的托管服务提供商)或您的字体路径'font_path' => './captcha/font.ttf'不正确。仔细检查它们。

答案 1 :(得分:0)

如果目录结构存在[WEB_ROOT] / img / captcha /:

$this->load->helper('captcha');
$this->data['captcha'] = create_captcha(array(
    'img_path'      => dirname(FCPATH) . DIRECTORY_SEPARATOR .'img'. DIRECTORY_SEPARATOR .'captcha'. DIRECTORY_SEPARATOR,
    'img_url'       => '/img/captcha/',
    'font_path'     => APPPATH . SYSDIR . DIRECTORY_SEPARATOR .'fonts'. DIRECTORY_SEPARATOR .'texb.ttf',
));