For smart Primates & ROBOTS (oh and ALIENS ).

Sunday, March 29, 2015

File upload in CodeIgniter

Problem:

How to upload file in CodeIgniter?
You can simply use $_FILES array to upload image. But if you want to use CodeIgniter library to upload file, then how can you achieve this? 

Solution:

You can use $this->load->helper('form'); to generate form.
After that configure using $config[], set this $config[] same as $this->load->library('upload', $config);
and upload like this
$this->upload->do_upload('transporter_image');

Error may occur during file upload so you can get error list by using

$his->upload->display_errors());
If file uploaded the get the information by this method:
$this->upload->data();

Example:

VIEW FILE
transporter_form.php
<html>
<head>
<title>File uploading in CodeIgniter</title>
</head>
<body>
<?php echo form_open_multipart('Transporter/transporterlist/');?>
<input type="file" name="transporter_image" size="20" />
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
============================================
CONTROLLER FILE
Transporter.php
<?php
class Transporter extends CI_Controller {
        public function __construct()
        {
                parent::__construct();
                $this->load->helper('form');
        }

        public function index()
        {
                $this->load->view('transporter_form', array('error' => ' ' ));
        }

        public function transporterlist ()
        {
        $config['upload_path']          = './images/transporter/';
            $config['allowed_types']        = 'gif|jpg|png';
            $config['max_size']             = 100;

            $config['max_width']            = 1024;
            $config['max_height']           = 768;
        $config['file_name']           = 'file_name.jpg';// set file name here
        $this->load->library('upload', $config);
        if(!$this->upload->do_upload('transporter_image')) {
                    $data['imgerror']= array('error' => $this->upload->display_errors());
        } else {
                    $data['imgsuccess'] = 'Image uploaded';//array('success' => $this->upload->data());
        }
        $this->load->view('successpage',$data);
        }
}
?>
==============================================
VIEW FILE
successpage.php
<html>
<head>
<title></title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<?php
    if(isset($imgsuccess)){
        echo $imgsuccess;
    }
?>

<ul>
<?php
if(isset($imgerror)) {
    foreach ($imgerror as $item => $value):?>
        <li><?php echo $item;?>: <?php echo $value;?></li>
<?php
    endforeach;
}
?>
</ul>
</body>
</html>








Share:

Prevent XSS in CodeIgniter

Problem:

How to prevent XSS Cross Site Scripting in CodeIgniter

Solution:

use $this->security->xss_clean($input_data); method
OR
set $config['global_xss_filtering']=TRUE;

Example:

$input_data = $this->security->xss_clean($input_data);
or add this line in config.php file
$config['global_xss_filtering'] = TRUE;
Share:

Binding Where IN Clause in CodeIgniter

Problem:

How to bind multiple and single value in where IN sql clause using CodeIgniter

Solution:

Pass array variable in query

Example:

Passing single numeric value using array.

$sql = "SELECT * FROM tbl_name WHERE id IN ? AND nm = ? AND code = ?";
$this->db->query($sql, array(array(1), 'nm123', 'c123'));

Passing multiple numeric value using array.
$sql = "SELECT * FROM tbl_name WHERE id IN ? AND nm = ? AND code = ?";
$this->db->query($sql, array(array(1, 2, 3), 'nm123', 'c123'));

Passing single string value using array.
$sql = "SELECT * FROM tbl_name WHERE id IN ? AND nm = ? AND code = ?";
$this->db->query($sql, array(array('a1'), 'nm123', 'c123'));

Passing multiple string value using array.
$sql = "SELECT * FROM tbl_name WHERE id IN ? AND nm = ? AND code = ?";
$this->db->query($sql, array(array('a1', 'a2', 'a3'), 'nm123', 'c123'));

Share:

Saturday, March 28, 2015

load model in view codeigniter

Problem:

How to load model in CodeIgniter view? It is not a good idea to load model in view, but sometime it is a requirement to load model in view.

Solution:

Create the instance of CodeIgniter as below:
$ci_inst =&get_instance();

Then load your model as below:
$ci_inst->load->model('model_name');

now you can access model as below:
$rs_truck=$ci_inst->model_name->function_method_name(parameter);

Example:

$ci_inst =&get_instance();
$ci_inst->load->model('truck_model');
$rs_truck=$ci->truck_model->get_trucks_by_transporter_id(1);
Share:

Wednesday, March 25, 2015

Email Blaster

Email Blaster
*Features
- Send unlimited emails.
- Send test email, so you can see your email format and looks.
- Show real time progress in counting sent emails.
- Show progress in percentage(%)
- Send email both format Text and HTML format.
- Alternate Solution of Cron Job(Less feature).
- Alternate Solution of SQL Agent Job(Less feature).
- Solution of Script Timeout.






















































Share:

Tuesday, March 24, 2015

Image Cropper

Image Cropper
How to use?
1- Click to "open" button & select image file.
2- Drag & select the portion of image.
3- Click on "select" button.
4- click on "save" button.
 
Image Cropper

Download here




























Share:

Monday, March 23, 2015

Text to speech

Text to speech



Text to speech












Download here:
Download











Share:

Custom library in CodeIgniter

Custom library in CodeIgniter:

CodeIgniter is a MVC PHP Framework. Do you know this framework is very fast PHP framework. It is designed to create a dynamic, flexible & SEO friendly web application.
Now days CodeIgniter is very famous MVC framework. In past time when you work in Core PHP with OOP; you have developed own custom library which have many utilities functions which you uses in different Projects. This custom library save your time and remove complexity.

Now you are moving to modern programming languages like CodeIgniter  framework. Now the question is how to use that custom library in this CodeIgniter framework?


See below class with having functions which is your custom library:
<?php
// Class name is "Myclass". but you can change it with any name
class Myclass {
   // Declare local variable
   var $temp;
   // This is constructor of "Myclass" here you can initialize local variables etc.
    public function __construct(){
       // set local variable value with single space.
       $this->temp='';
    }
 
   // this is method will call after delete record in CodeIgniter Controller
    public function message_del() {
        // Add here your usefull code
        $this->temp='    Record Deleted.';
        return $this->temp;
    }
 
// this is method will call after edit record in CodeIgniter Controller
    public function message_edit() {
        // Add here your usefull code
           $this->temp='    Record Edited.';
        return $this->temp;
    }

   // this is method will call after add record in CodeIgniter Controller
    public function message_add() {
            // Add here your usefull code
        $this->temp='    Record Added.';
        return $this->temp;
    }
}
?>


Now how to use above class in CodeIgniter?  Follow below steps o how to use.
//Create Myclass.php file in codeigniter "application\libraries\"

//Myclass.php
<?php
// this is default CodeIgniter code Do not delete it
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Myclass {
   // Declare local variable , note that $temp variable will return from it's class's methods
   var $temp;
   var $CI;
   public function __construct(){
      // set CodeIgniter instance object here. but it is not necessary.
       $this->CI =&get_instance();
       // set local variable value with single space.
       $this->temp='';
    }
     // this is method will call after delete record in CodeIgniter Controller
    public function message_del() {
        // Add here your code which delete record from mysql database.
        $this->temp='    Record Deleted.';
        return $this->temp;
    }
 
// this is method will call after edit record in CodeIgniter Controller
    public function message_edit() {
         // Add here your code which edit record in mysql database.
           $this->temp='    Record Edited.';
        return $this->temp;
    }

   // this is method will call after add record in CodeIgniter Controller
    public function message_add() {
            // Add here your code which add record in mysql database.
        $this->temp='    Record Added.';
        return $this->temp;
    }
}
?>

Now how to use above class in any controller class
Create Category.php controller file in "application\controllers\" folder
Category.php


<?php

// this is default CodeIgniter code Do not delete it
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// This is the Controller class it must always extends with  CI_Controller
class Category extends CI_Controller {

// This the default constructor with same name as Category class
    function Category() {
        //it is necessary to call parent class's (CI_Controller) constructor
        parent::__construct();

        // this is the your Myclass class in Myclass.php file in "application\libraries\" folder
        // this is the way to load your custom class. Make sure it should be small case letter
        $this->load->library('myclass');
    }
    public function index() {
        // use own logic here, you can make empty it.
    }
    // suppose you want to use MyClass.php >message_add method here
    public function addrecord() {
        // this is the way to calling method message_add()
         $data['ans']=$this->myclass->message_add();
//now load "result_view" with ans data
        $this->load->view('result_view',$data);
    }
    // suppose you want to use MyClass.php method message_edit() here
    public function editrecord() {
        // this is the way to calling method message_edit()
        $data['ans']=$this->myclass-message_edit();
//now load "result_view" with ans data
       $this->load->view('result_view',$data);

    }
    // suppose you want to use MyClass.php method message_del() here
    public function deleterecord() {
        // this is the way to calling method message_del()
         $data['ans']=$this->myclass-message_del();
        //now load "result_view" with ans data
        $this->load->view('result_view',$data);
    }   
}
?>



Now how to use above class in any controller class
Create 
result_view.php  view file in "application\views\" folder
result_view.php

<?php
//now access the variable  "$ans"  which  set in  $data['ans']=$this->myclass-message_del();  
// and load it in the view as $this->load->view('result_view',$data);

if(isset($ans)) {
          echo $ans;

       }
?>


Share:

Sunday, March 22, 2015

Fatal error: Call to a member function num_rows() on a non-object in

Problem:

While working with CodeIgniter you can get this "Fatal error: Call to a member function num_rows() on a non-object in...." error. You can also surprise that every thing is okay and every thing is okay in your sql.

Solution:

Some time you used different my sql Database name in local and production server, and you have mentioned wrong database name in your config.php file, So just verify the Database name and this error will gone.




Share:

Friday, March 20, 2015

Image Combiner


Combine all images from selected folder into one image.
This is a Free desktop software to combine multiple images into one single image.
There are no limit to combine , so you can combine unlimited images.
You need to select the folder where all images are existing.
This tool automatically get the highest width of image.














Download Image Combiner




Share:

Ads Inside Post

Powered by Blogger.

Archive