【问题标题】:CodeIgniter Captcha Refuses to WorkCodeIgniter Captcha 拒绝工作
【发布时间】:2014-06-03 22:31:23
【问题描述】:

我知道有一万亿个类似的问题,但没有一个能够帮助我。这是小示例代码:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Captcha extends CI_Controller {

public function index(){ 

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

    $cap_settings = array(
        'word'          => 'Random word',
        'img_path'      => './images/captcha/',
        'img_url'       => base_url().'captcha',
        'font_path'     => './fonts/hardcorium.ttf',
        'img_width'     => '300',
        'img_height'    => '50',
        'expiration'    => 1800
    );

    $cap = create_captcha($cap_settings);

    echo $cap['image'];
}
}

这是我所知道的:

  1. 使用 WAMP 本地主机
  2. GD2 库已加载 (php_gd2)
  3. 我在控制器的索引上创建了具有相同路径的 html 链接 显示为所需文件,它们可以正常工作
  4. 使用过绝对路径和相对路径
  5. Captcha 文件夹存在于应用程序文件夹中

什么都没有显示,firebugs 也没有抛出错误,CI 也没有。我不知道可能出了什么问题。

【问题讨论】:

  • 验证码文件夹是否存在?
  • @tomexsans 是的,该文件夹位于应用程序文件夹中。
  • 改用APPPATH.'/images/captcha';,错误是它正在尝试在您的根目录中查找文件夹。
  • @tomexsans 我已经这样写了:base_url().'application/images/captcha/' 仍然没有显示。
  • base_url 用于链接/URL,链接不能用作目录路径,我说的是img_path 而不是img_url

标签: php codeigniter wamp captcha


【解决方案1】:

在视图页面中,表单必须以下列方式:-

&lt;?php echo form_open_multipart(path,'class="form-horizontal"'); ?&gt;

captcha文件夹必须有777权限,这样captcha才能读也写。您可以通过以下方式授予权限:-

在终端输入下面一行

sudo chmod -R 777 path

请检查以上两点,并正确检查图片路径。

一定能帮到你

【讨论】:

    【解决方案2】:
    1. 使用权限 777 在 root 上创建文件夹验证码
    2. 在根目录下创建字体文件夹并将字体文件放入其中。
    3. $config['base_url'] = 'http://localhost/yourproject/';在config.php中

    class Captcha extends CI_Controller {
    
    public function index(){ 
    
    $this->load->helper('captcha');
    $this->load->helper('url');
    
    $cap_settings = array(
        'word'          => 'Random word',
        'img_path'      => './captcha/',
        'img_url'       => base_url().'/captcha/',
        'font_path'     => base_url().'/fonts/hardcorium.ttf',
        'img_width'     => '300',
        'img_height'    => '50',
        'expiration'    => 1800
    );
    
    $cap = create_captcha($cap_settings);
    
    echo $cap['image'];
     }
    }
    

    https://stackoverflow.com/a/39637942/2107318

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 2013-08-02
      • 2014-12-10
      相关资源
      最近更新 更多