首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >create_captcha - function返回false - Codeigniter

问create_captcha - function返回false - Codeigniter
EN

Stack Overflow用户
提问于 2018-01-20 22:06:26
回答 2查看 823关注 0票数 0

这是我的目录结构:

​

​

我的代码如下:

代码语言:javascript
复制
$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)。

EN

回答 2

Stack Overflow用户

发布于 2018-01-21 09:03:50

这里有两种可能性。要么你没有安装GD扩展(如果你在一个支持apt的Linux环境中,试试apt-get install php-gd或apt-get install php7.0-gd (取决于你的PHP版本),或者向你的主机提供商咨询),要么你的字体路径'font_path' => './captcha/font.ttf'不正确。仔细检查他们两个。

票数 1
EN

Stack Overflow用户

发布于 2020-10-20 00:03:21

如果目录结构存在WEB_ROOT/img/captcha/,则可以执行此操作:

代码语言:javascript
复制
$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',
));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48357073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档