Welcome Guest, Not a member yet? Register   Sign In
CI 2.0 - Image Show Problem
#1

[eluser]Molchy[/eluser]
Hi,

I switched one application from CI 1.7.2 to CI 2.0 and hit a wall Sad. I use on login page captcha helper but image is not shown (empty image box) or any kind of msg.

I checked:
- Image path OK
- Image file Permissions OK

But when i go to image path via browser DEFAULT CONTROLLER IS SHOWN and not image on that path ???????

Everything worked perfectly in CI 1.7.2 but not in CI 2.0 can you please help me?

ROUTES.PHP:
Code:
$route['admin'] = 'admin/index'; // ADMIN
$route['admin/(:any)'] = 'admin/index'; // ADMIN -> MODUL
$route['(:any)'] = 'main/index'; // PAGE
$route['default_controller'] = 'main';
$route['404_override'] = '';


HTACCES CODE:
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^theme.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteCond %{HTTP_HOST} !^MY_URI\.com [NC]
    RewriteRule ^(.*)$ MY_URI/$1 [R=301,NC,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
#2

[eluser]mariuskmc[/eluser]
I use a model
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Captcha model
*
* Interacts with the captcha table and creates and validates
* the captcha using the captcha plugin
*
* @package        openviz
* @subpackage          admin
* @author        Robert Tooker
* @since        Version 1.0
*/

class Captcha_model extends CI_Model {

    /**
     * Defines the table for the model, used for active record functions
     * @access private
     * @var string
     */
    private $_model_table = 'captcha';

    /**
     * How long images and database records will be retained
     * @access private
     * @var integer
     */
    private $_expiration = 3600;

    /**
     * Auto increment field, primary key
     * @access public
     * @var integer
     */
    public $id = null;

    /**
     * The time the captcha was created (unix timestamp)
     * @access public
     * @var integer
     */
    public $captcha_time = 0;

    /**
     * The IP address of the user when the captcha was created
     * @access public
     * @var text
     */
    public $ip_address = '';

    /**
     * The word shown in the captcha image
     * @access public
     * @var text
     */
    public $word = '';

    /**
     * Constructor
     */
    function __construct() {
        //parent::Model();
        parent::__construct();
    }

    /**
     * Makes a captcha image
     * @param text $ip_address the IP address of the user
     * @return text a link to the image or an error message if image could not be created
     */
    function make($ip_address) {
        //$this->load->plugin( 'captcha' );
        $this->load->helper('captcha');
        
        $parameters = array(
            'img_path' => './captcha/',
            'img_url' => base_url() . 'captcha/',
            'img_width' => 150,
            'img_height' => 30,
      
            'expiration' => $this->_expiration
        );

        $captcha = create_captcha( $parameters );
        if ( $captcha ) {
            $this->id = null;
            $this->captcha_time = $captcha['time'];
            $this->ip_address = $ip_address;
            $this->word = $captcha['word'];

            $this->db->insert($this->_model_table, $this->model_to_array());
            $this->id = $this->db->insert_id();
        } else {
            return "Could not make captcha." ;
        }
        return $captcha['image'] ;
    }

    /**
     * Checks the response to a captcha image
     * @param text $ip_address the ip address of the response
     * @param text $response the response which should match the word
     * @return bool if the response is correct or not
     */
    function check($ip_address, $response) {
        $this->db->where('captcha_time <', time() - $this->_expiration);
        $this->db->delete($this->_model_table);

        //checking input
        $this->db->where('ip_address', $ip_address);
        $this->db->where('word', $response);
        $query = $this->db->get($this->_model_table);

        if ( $query->num_rows() > 0 ) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Assigns the values of a captcha array to the captcha model
     *
     * Receives an array and sets matching properties of the model, leaving
     * unmatched properties intact. Useful for receiving a subset of fields
     * from a page post and applying an update using active record.
     *
     * @access public
     * @param mixed $data an associative array of datafield properties with the key representing the property name
     */
    function array_to_model($data) {
        if (isset($data['id'])) $this->id = $data['id'];
        if (isset($data['captcha_time'])) $this->captcha_time = $data['captcha_time'];
        if (isset($data['ip_address'])) $this->id = $data['ip_address'];
        if (isset($data['word'])) $this->id = $data['word'];
    }

    /**
     * Returns the model's database fields as an associative array
     *
     * @access public
     * @return mixed an associative array of datafield properties with the key representing the property name
     */
    function model_to_array() {
        $data['id'] = $this->id;
        $data['captcha_time'] = $this->captcha_time;
        $data['ip_address'] = $this->ip_address;
        $data['word'] = $this->word;
        return $data;
    }

}

in controler i have
Code:
// load captcha model with default database connection
        $this->load->model('Captcha_model', '', 'default');
        // add the captcha image to the view data
        $data['captcha_img']=$this->Captcha_model->make($this->input->ip_address());


// and for validation
$this->form_validation->set_rules('captcha_text', 'Cod Security code', 'required|callback_validate_captcha');

in view
Code:
&lt;?
$form_captcha_text = form_input(array(
    'name'=>'captcha_text'
    , 'id'=>'captcha_text'
    , 'value'=>''
    , 'maxlength'=>8
    , 'size'=>14
    , 'class'=>'texta')
);
?&gt;

&lt;?php echo $captcha_img; ?&gt; = &lt;?php echo $form_captcha_text; ?&gt;


database
Code:
CREATE TABLE IF NOT EXISTS `captcha` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `captcha_time` int(10) unsigned NOT NULL,
  `ip_address` varchar(16) NOT NULL DEFAULT '0',
  `word` varchar(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `ip_address` (`ip_address`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
#3

[eluser]Molchy[/eluser]
Tnx but found a problem Big Grin

Application folder contained htaccess file with:
deny from all


Grrrrrrrrrrrrrrr why did i sow it before Big Grin i was looking for problem whole morning and it was this htaccess block Big Grin
#4

[eluser]mariuskmc[/eluser]
happens at all Smile




Theme © iAndrew 2016 - Forum software by © MyBB