0

i've been using captcha for codeigniter i working fine on my PC but somehow when i uploaded to the server it not generating the image, i've been trying with suggestion from other post from stackoverflow but it doesn't work

I've been check below point

  1. GD is already enable
  2. i already do the chmod 755 to assets directory with recursive mode

Please find below my code in controller

public function captcha_config() {
                $this->load->helper(array('captcha','form'));
                $vals = array(
                                'img_path' => '/var/www/html/assets/files/captcha/',
                                'img_url' => base_url().'assets/files/captcha/',
                                'img_width' => 150,
                                'img_height' => 30,
                                'expiration' => 7200
                        );
                        $cap = create_captcha($vals);
                        $this->session->set_userdata('capt',md5($cap['word']));
                        $image = $cap['image'];

                        //$data['captcha_img'] = $cap['image'];

                        //return $image;
                        var_dump($cap); //it shown bool(false)
        }

the result is

bool(false)

I've been change the path into this below, but also not working.

./assets/files/captcha/

-------------------------- Update 06-04-2016 --------------------------------

I got another clue

After i do debugging in helper (captcha_helper) i change some return False to be debugging mode. it shown following error

Message: imagejpeg(/var/www/html/assets/files/captcha/1465012057.5767.jpg): failed to open stream: Permission denied

I've done change the captcha directory to be chmod 777 but it seems doesn't work.

i've done change the ownership to be apache, i'm using this script to check the ownership from web, but still doesn't work ?

<?php echo exec('whoami'); ?>

Why the captcha cannot write into that directory ?

Amir Rachman
  • 225
  • 5
  • 15
  • There are 4 places where it returns false in the `create_captcha()` function. If the image path/url have not been set (your code set this so not a problem). If the image path is not a directory (I hope you have create a dir or this will be the issues). If the image path is not writable (I suspect this is your issue 0755 means it is writable by your user but only read/execute for other users, change permissions to 0777 to get around this). And finally if the GD lib is not installed (You claim it already is so should not be an issue). Good Luck :) – mic Jun 03 '16 at 15:55
  • have you tried this `assets/files/captcha/` – Rejoanul Alam Jun 03 '16 at 15:56
  • @mic : i've been check the path, create a directory, make the directory writeable using chmod 666, GD already installer (i saw on PHP info), what was the issue ?, it's confusing – Amir Rachman Jun 03 '16 at 16:00
  • @RejoanulAlam : i've been change as your suggest but it doesn't impact – Amir Rachman Jun 03 '16 at 16:00
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Jun 12 '16 at 10:12

4 Answers4

0

Your i img_path is wrong. Try with this

 'img_path' => './assets/files/captcha/',

CodeIgniter Captcha Helper Example - FormGet.com

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
  • hi @abdulla please see on my question above, i've been change into this also, but it's not working – Amir Rachman Jun 04 '16 at 00:03
  • @abdulla, relative paths are dangerous in includes. The reason for that, and the way to go, is explained here : https://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory – Vic Seedoubleyew Jun 12 '16 at 10:13
0

I've found clue because of this article, it is because SELinux is active on Centos 7.

https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

Amir Rachman
  • 225
  • 5
  • 15
  • Indeed, and you can troubleshooting this kind of issues, and find solutions for them, here : https://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory – Vic Seedoubleyew Jun 12 '16 at 10:13
0

Yes. Exactly due to wrong image path it showing this error. use exact path and url in codeigniter its fine.

 'img_path'      => APPPATH.'../assets',
 'img_url'       => base_url().'/assets',
0

First test if SELinux is active:
$ sestatus

If output is some like this:

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      33

Then disable it temporaly:
$ sudo setenforce Permissive

Try to generate a new captcha. If it works the cause is a SELinux permission problem.

Enable SELinux again:
$ sudo setenforce Enforcing

And apply a read/write policy to the captcha destination directory, in your case "/var/www/html/assets/files/captcha/"

$ sudo chcon -R -t httpd_sys_content_rw_t /var/www/html/assets/files/captcha/

Test again.

Francisco
  • 143
  • 1
  • 8