S.M_Emamian
S.M_Emamian

Reputation: 17383

create_captcha - function returns false - Codeigniter

This is my directory structure:

enter image description here

My code is the following:

$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;

but my output returns bool(false).

Upvotes: 0

Views: 1436

Answers (2)

aLx13
aLx13

Reputation: 781

This works if the directory structure exists [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',
));

Upvotes: 0

BudwiseЯ
BudwiseЯ

Reputation: 1826

There's two possibilities here. Either you don't have the GD extension installed (if you're on a apt - enabled Linux-environment, try apt-get install php-gd or apt-get install php7.0-gd (depending on your PHP - version) or ask your hosting provider about it) or your font path 'font_path' => './captcha/font.ttf' is incorrect. Double check them both.

Upvotes: 1

Related Questions